-
Notifications
You must be signed in to change notification settings - Fork 1
/
models.py
72 lines (61 loc) · 2.32 KB
/
models.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
from dashboard.models import ActionDashboardManager
from django.contrib.auth import get_user_model
from django.db import models
from statistic.models import ActionMonthStatisticManager
from utils.models import TimeStampedModel
User = get_user_model()
class Action(TimeStampedModel):
text = models.CharField(max_length=140,
null=False,
verbose_name="Text",
help_text="Enter an action title (e.g. Book Reading)")
unit = models.CharField(max_length=50,
null=False,
verbose_name="Unit",
help_text="Enter a unit (e.g. pages)")
user = models.ForeignKey(User,
null=False,
on_delete=models.CASCADE,
related_name='actions')
COLORS = (
(1, 'orange'),
(2, 'red-orange'),
(3, 'radical-red'),
(4, 'gray'),
(5, 'green'),
(6, 'blue'),
(7, 'purple'),
)
color = models.IntegerField(
choices=COLORS,
default=1,
verbose_name="Color",
help_text="Choose a color of progress bar"
)
objects = models.Manager()
dashboard = ActionDashboardManager()
month_statistic = ActionMonthStatisticManager()
def __str__(self):
return '{} ({})'.format(self.text[:75],
self.unit)
class Meta:
verbose_name = 'action'
verbose_name_plural = 'actions'
ordering = ('-created', )
class Record(TimeStampedModel):
action = models.ForeignKey(Action,
on_delete=models.CASCADE,
null=False,
verbose_name="Action",
help_text="Choose your action",
related_name='records')
value = models.PositiveIntegerField(null=False,
verbose_name="Value",
help_text="Enter a value of record")
def __str__(self):
return '{} {}'.format(self.value,
self.action.unit[:75])
class Meta:
verbose_name = 'record'
verbose_name_plural = 'records'
ordering = ('-created', )