Coverage for mycalendar / models.py: 84%
19 statements
« prev ^ index » next coverage.py v7.13.0, created at 2025-12-21 13:48 +0900
« prev ^ index » next coverage.py v7.13.0, created at 2025-12-21 13:48 +0900
1'''Model module.
3Copyright ycookjp
5https://github.com/ycookjp/
7'''
8from django.db import models
9from django.db.models import UniqueConstraint
11class MyCalendar(models.Model):
12 '''カレンダークラス
14 Attributes:
15 id (int): ID
16 user (str): ユーザー名
17 year (int): カレンダーの年
18 month (int): カレンダーの月
19 day (int): カレンダーの日
20 note (str): コメント
22 '''
23 id = models.IntegerField(primary_key=True)
24 user = models.CharField(max_length=128)
25 year = models.IntegerField()
26 month = models.IntegerField()
27 day = models.IntegerField()
28 note = models.TextField(max_length=512)
29 unique_together = (('user', 'year', 'month', 'day'),)
31 class Meta:
32 db_table = 'my_calendar'
33 UniqueConstraint(
34 name = 'unique_mycalender',
35 fields=['user', 'year', 'month', 'day']
36 )
39 @classmethod
40 def deserialize(cls, json_data: dict):
41 '''ディクショナリ形式のJSONデータをMyCalendarモデルのインスタンスに変換する。
43 Args:
44 json_data (dict): ディクショナリ形式のJSONデータを指定する。
45 Returns:
46 MyCalendar: MyCalendarのインスタンスを返却する。
48 '''
49 mycalendar = MyCalendar(
50 id = json_data.get("id"),
51 user = json_data.get('user'),
52 year = int(json_data.get('year')),
53 month = int(json_data.get('month')),
54 day = int(json_data.get('day')),
55 note = json_data.get('note')
56 )
57 return mycalendar
59 def __str__(self):
60 '''レコードの文字列表現を返す。
61 '''
62 return f'[{self.user}]{self.year}-{self.month}-{self.day}'