Coverage for apps/site_setting/models.py : 52%
Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
1from django.core.exceptions import ValidationError
2from django.db import models
5class SingletonModel(models.Model):
6 class Meta:
7 abstract = True
9 def save(self, *args, **kwargs):
10 self.pk = 1
11 super(SingletonModel, self).save(*args, **kwargs)
13 def delete(self, *args, **kwargs):
14 pass
16 @classmethod
17 def load(cls):
18 obj, created = cls.objects.get_or_create(pk=1)
19 return obj
22class SiteSetting(SingletonModel):
23 start_date = models.DateField()
24 end_date = models.DateField()
25 child_family_start_date = models.DateField("Child family support/participation start date", null=True)
26 child_family_end_date = models.DateField("Child family support/participation end date", null=True)
28 def clean(self):
29 if self.start_date and self.end_date and \
30 self.start_date > self.end_date:
31 raise ValidationError(
32 'Start Date shouldn\'t be greater then End Date'
33 )
34 if self.child_family_start_date and self.child_family_end_date and \
35 self.child_family_start_date > self.child_family_end_date:
36 raise ValidationError(
37 'Start Date shouldn\'t be greater then End Date'
38 )
40 def __str__(self):
41 return 'Site Settings'