Hide keyboard shortcuts

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.db import models 

2 

3# Create your models here. 

4 

5 

6class District(models.Model): 

7 name = models.CharField(max_length=255, unique=True) 

8 code = models.CharField(max_length=255, unique=True) 

9 

10 class Meta: 

11 ordering = ['name'] 

12 

13 def __str__(self): 

14 return '{} ({})'.format(self.name, self.code) 

15 

16 

17class Municipality(models.Model): 

18 name = models.CharField(max_length=255) 

19 code = models.CharField(max_length=255, unique=True) 

20 district = models.ForeignKey( 

21 District, 

22 on_delete=models.CASCADE, 

23 related_name='municipalities', 

24 ) 

25 

26 class Meta: 

27 ordering = ['name'] 

28 

29 def __str__(self): 

30 return '{} ({})'.format(self.name, self.code) 

31 

32 

33class Project(models.Model): 

34 name = models.CharField(max_length=255) 

35 number = models.CharField(unique=True, null=True, blank=True, max_length=10) 

36 district = models.ForeignKey( 

37 District, on_delete=models.CASCADE, related_name='projects', 

38 null=True, 

39 ) 

40 municipalities = models.ManyToManyField( 

41 Municipality, 

42 blank=True, 

43 ) 

44 

45 # Cordinates 

46 long = models.DecimalField(max_digits=9, decimal_places=6, null=True) 

47 lat = models.DecimalField(max_digits=9, decimal_places=6, null=True) 

48 

49 child_marriage_count = models.IntegerField(default=0) 

50 

51 def __str__(self): 

52 return f'{self.name} - {self.number}' 

53 

54 @property 

55 def recent_report(self): 

56 return self.reports.order_by('-date').first()