summaryrefslogtreecommitdiff
path: root/app/sightings
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/sightings
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/sightings')
-rw-r--r--app/sightings/admin.py4
-rw-r--r--app/sightings/models.py20
2 files changed, 21 insertions, 3 deletions
diff --git a/app/sightings/admin.py b/app/sightings/admin.py
index 9cd0fef..433d465 100644
--- a/app/sightings/admin.py
+++ b/app/sightings/admin.py
@@ -46,3 +46,7 @@ class SightingAdmin(OSMGeoAdmin):
map_height = 425
map_template = 'gis/admin/osm.html'
openlayers_url = '/static/admin/js/OpenLayers.js'
+
+ class Media:
+ js = ('next-prev-links.js',)
+
diff --git a/app/sightings/models.py b/app/sightings/models.py
index 96e0b5e..792c52b 100644
--- a/app/sightings/models.py
+++ b/app/sightings/models.py
@@ -1,5 +1,6 @@
import datetime
from django.urls import reverse
+from django.apps import apps
from django.template.defaultfilters import slugify
from django.contrib.gis.db import models
from django.contrib.auth.models import User
@@ -82,14 +83,14 @@ class Sighting(models.Model):
ap = models.ForeignKey(AP, on_delete=models.CASCADE)
point = models.PointField(blank=True)
location = models.ForeignKey(Location, on_delete=models.CASCADE, blank=True)
- date = models.DateTimeField('Date', default=timezone.now)
+ pub_date = models.DateTimeField('Date', default=timezone.now)
seen_by = models.ManyToManyField(User)
images = models.ManyToManyField(LuxImage, blank=True)
#audio = models.ManyToManyField(BirdAudio, blank=True)
class Meta:
- ordering = ["-date", ]
- get_latest_by = "date"
+ ordering = ["-pub_date", ]
+ get_latest_by = "pub_date"
@property
def state(self):
@@ -113,6 +114,19 @@ class Sighting(models.Model):
'''Get the site's latitude.'''
return self.point.y
+ @property
+ def get_previous_admin_url(self):
+ n = self.get_previous_by_pub_date()
+ return reverse('admin:%s_%s_change' %(self._meta.app_label, self._meta.model_name), args=[n.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_small_image(self):
for img in self.images.all():
for size in img.sizes.all():