summaryrefslogtreecommitdiff
path: root/app/locations/models.py
diff options
context:
space:
mode:
Diffstat (limited to 'app/locations/models.py')
-rw-r--r--app/locations/models.py22
1 files changed, 18 insertions, 4 deletions
diff --git a/app/locations/models.py b/app/locations/models.py
index 203e175..6e8db7c 100644
--- a/app/locations/models.py
+++ b/app/locations/models.py
@@ -128,6 +128,12 @@ class Location(models.Model):
pub_date = models.DateTimeField('Date published')
geometry = models.MultiPolygonField(srid=4326)
parent = models.ForeignKey('self', on_delete=models.CASCADE, blank=True, null=True)
+ state_name = models.CharField(max_length=50, blank=True)
+ state_slug = models.CharField(max_length=50, blank=True)
+ country_name = models.CharField(max_length=50, blank=True)
+ country_slug = models.CharField(max_length=50, blank=True)
+ region_name = models.CharField(max_length=50, blank=True)
+ region_slug = models.CharField(max_length=50, blank=True)
class Meta:
ordering = ('-pub_date',)
@@ -137,10 +143,10 @@ class Location(models.Model):
return self.name
def comma_name(self):
- if self.state.country.name == "United States":
- return self.state
+ if self.country_name == "United States":
+ return self.state_name
else:
- return self.state.country
+ return self.country_name
@property
def get_previous_admin_url(self):
@@ -155,8 +161,16 @@ class Location(models.Model):
return ''
def get_absolute_url(self):
- return "/locations/%s/%s/%s/" % (self.state.country.slug, self.state.slug, self.slug)
+ return "/locations/%s/%s/%s/" % (self.country_slug, self.state_slug, self.slug)
+ def save(self, *args, **kwargs):
+ self.state_name = self.state.name
+ self.state_slug = self.state.slug
+ self.country_name = self.state.country.name
+ self.country_slug = self.state.country.slug
+ self.region_name = self.state.country.lux_region.name
+ self.region_slug = self.state.country.lux_region.slug
+ super(Location, self).save()
class Route(models.Model):
"""Model to hold routes for longer trips"""