summaryrefslogtreecommitdiff
path: root/app/locations/models.py
diff options
context:
space:
mode:
authorluxagraf <sng@luxagraf.net>2018-02-05 13:38:59 -0600
committerluxagraf <sng@luxagraf.net>2018-02-05 13:38:59 -0600
commit3398e7349e2bafddaa491c01f4c16c6dae14cd00 (patch)
tree0ae25201ce6fc50146dff819b03819ddce148cfe /app/locations/models.py
parentad112641f01a0fd36d0b738b6903dea3eadbf000 (diff)
abstracted the next prev links into utils so now they work for every
model that implements a get_%S_admin_link method and loads the JS
Diffstat (limited to 'app/locations/models.py')
-rw-r--r--app/locations/models.py20
1 files changed, 19 insertions, 1 deletions
diff --git a/app/locations/models.py b/app/locations/models.py
index e9c79e5..f9a3e5b 100644
--- a/app/locations/models.py
+++ b/app/locations/models.py
@@ -1,5 +1,7 @@
import json
import requests
+from django.urls import reverse
+from django.apps import apps
from django.contrib.gis.geos import GEOSGeometry, fromstr, MultiPolygon
from django.contrib.gis.db import models
from django.contrib.sitemaps import Sitemap
@@ -117,9 +119,13 @@ class Location(models.Model):
state = models.ForeignKey(State, on_delete=models.CASCADE)
name = models.CharField(max_length=50, )
slug = models.SlugField()
- pub_date = models.DateTimeField('Date published', null=True)
+ pub_date = models.DateTimeField('Date published')
geometry = models.MultiPolygonField(srid=4326)
+ class Meta:
+ ordering = ('-pub_date',)
+ get_latest_by = 'pub_date'
+
def __str__(self):
return self.name
@@ -129,6 +135,18 @@ class Location(models.Model):
else:
return self.state.country
+ @property
+ def get_previous_admin_url(self):
+ return reverse('admin:%s_%s_change' %(self._meta.app_label, self._meta.model_name), args=[self.get_previous_by_pub_date().id] )
+
+ @property
+ def get_next_admin_url(self):
+ model = apps.get_model(app_label=self._meta.app_label, model_name=self._meta.model_name)
+ try:
+ return reverse('admin:%s_%s_change' %(self._meta.app_label, self._meta.model_name), args=[self.get_next_by_pub_date().pk] )
+ except model.DoesNotExist:
+ return ''
+
def get_absolute_url(self):
return "/locations/%s/%s/%s/" % (self.state.country.slug, self.state.slug, self.slug)