diff options
author | luxagraf <sng@luxagraf.net> | 2018-02-05 13:38:59 -0600 |
---|---|---|
committer | luxagraf <sng@luxagraf.net> | 2018-02-05 13:38:59 -0600 |
commit | 3398e7349e2bafddaa491c01f4c16c6dae14cd00 (patch) | |
tree | 0ae25201ce6fc50146dff819b03819ddce148cfe /app/locations | |
parent | ad112641f01a0fd36d0b738b6903dea3eadbf000 (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')
-rw-r--r-- | app/locations/admin.py | 7 | ||||
-rw-r--r-- | app/locations/models.py | 20 |
2 files changed, 24 insertions, 3 deletions
diff --git a/app/locations/admin.py b/app/locations/admin.py index c3419b1..4a52778 100644 --- a/app/locations/admin.py +++ b/app/locations/admin.py @@ -3,6 +3,7 @@ from django.contrib.gis.admin import OSMGeoAdmin from locations.models import Region, Country, Location, State, Route, CheckIn from utils.widgets import OLAdminBase +from utils.util import get_latlon class RegionAdmin(OSMGeoAdmin): list_display = ('name', 'slug') @@ -183,8 +184,7 @@ class LocationAdmin(OSMGeoAdmin): }), ) # options for OSM map Using custom ESRI topo map - default_lon = -9285175 - default_lat = 4025046 + default_lat, default_lon = get_latlon() default_zoom = 6 units = True scrollable = False @@ -193,6 +193,9 @@ class LocationAdmin(OSMGeoAdmin): map_template = 'gis/admin/osm.html' openlayers_url = '/static/admin/js/OpenLayers.js' + class Media: + js = ('next-prev-links.js',) + admin.site.register(Location, LocationAdmin) 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) |