Newer
Older
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
from django.db import models
from django.core.urlresolvers import reverse
from staff.behaviors import WhiteLabelClientMixin, TimeStampedMixin
from .managers import LocationManager
class Location(WhiteLabelClientMixin):
"""
Physical location to be related to WCLs.
"""
code = models.CharField(max_length=64)
client = models.ForeignKey('clients.Client', related_name='locations', blank=True, null=True)
subtitle = models.CharField(max_length=128, blank=True)
address = models.CharField(max_length=512)
postal_code = models.CharField(max_length=512, blank=True)
main_phone = models.CharField(max_length=32, blank=True)
city = models.CharField(max_length=512, blank=True)
description = models.TextField(blank=True)
objects = LocationManager()
class Meta:
unique_together = ('white_label_client', 'code',)
ordering = ('-code',)
def __str__(self):
return '%s, %s' % (self.address, self.city)
def get_absolute_url(self):
return reverse('locations:detailview', args=(self.code,))
def get_edit_url(self):
return reverse('locations:editview', args=(self.code,))
class GeoLocation(TimeStampedMixin):
"""
Geocode which links `Location` objects to the 2D map.
"""
location = models.OneToOneField('locations.Location')
latitude = models.CharField(max_length=64)
longitude = models.CharField(max_length=64)
class LocationObject(TimeStampedMixin):
"""
An physical object can be assigned to a `Location` object.
"""
location = models.ForeignKey('locations.Location', related_name='location_objects')
code = models.CharField(max_length=64, blank=True)
name = models.CharField(max_length=255)
description = models.TextField(blank=True)
def __str__(self):
_str = self.name
if self.code:
_str += ' (%s)' % self.code
return _str