-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmodels.py
More file actions
33 lines (26 loc) · 1.11 KB
/
models.py
File metadata and controls
33 lines (26 loc) · 1.11 KB
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
from django.db import models
# Create your models here.
class CrimeKey(models.Model):
offense = models.CharField(max_length=200,blank=True,unique=True)
category = models.CharField(max_length=200)
def json(self):
return {
'offense': self.offense,
'category': self.category,
'incidents': [incident.json() for incident in Incident.objects.all().order_by('-date')]
}
def __unicode__(self):
return self.category
class Incident(models.Model):
address = models.CharField(max_length=200,blank=True)
caseno = models.CharField(max_length=200,blank=True)
date = models.DateTimeField('date and time occured')
offense = models.ForeignKey(CrimeKey, to_field="offense")
ward = models.CharField(max_length=200,blank=True)
lat = models.FloatField(blank=True)
long = models.FloatField(blank=True)
def json(self):
fields = ('address', 'caseno', 'date', 'offense__category', 'offense', 'ward', 'lat', 'long')
return dict((field, self.__dict__[field]) for field in fields)
def __unicode__(self):
return self.offense