summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorluxagraf <sng@luxagraf.net>2018-06-08 20:53:14 -0500
committerluxagraf <sng@luxagraf.net>2018-06-08 20:53:14 -0500
commit90822f204979663c79444ef8e89bda4701b8defb (patch)
treeb7de5c94ffc42fa71f7c822ff0c92f2b9bcbb55f
parenta32a107db3fe5b5c0742b2ba3f6a767f427fec5e (diff)
got inline map working
-rw-r--r--app/sightings/admin.py37
1 files changed, 31 insertions, 6 deletions
diff --git a/app/sightings/admin.py b/app/sightings/admin.py
index ce1c66a..03aaa83 100644
--- a/app/sightings/admin.py
+++ b/app/sightings/admin.py
@@ -1,13 +1,13 @@
+import copy
from django.contrib import admin
from django.contrib.gis.admin import OSMGeoAdmin
-from django.contrib.gis.db.models import PointField
from .models import APClass, AP, Sighting
from photos.forms import GalleryForm
from utils.util import get_latlon
from utils.widgets import CustomSelectMultiple, LGEntryForm
from .forms import SightingsForm
-from mapwidgets.widgets import GooglePointFieldInlineWidget
+from django.contrib.admin.options import FORMFIELD_FOR_DBFIELD_DEFAULTS
class GalleryFormPlus(GalleryForm):
def __init__(self, *args, **kwargs):
@@ -25,12 +25,37 @@ class APClassAdmin(admin.ModelAdmin):
list_filter = ('kind',)
-class SightingInline(admin.StackedInline):
+class SightingInline(OSMGeoAdmin, admin.StackedInline):
+ """
+ This is very fragile and probably a bad idea since I copied this
+ code straight from Django and it may change, but it works for now
+ """
model = Sighting
extra = 1
- formfield_overrides = {
- PointField: {"widget": GooglePointFieldInlineWidget}
- }
+ lat, lon = get_latlon()
+ default_lon = lon
+ default_lat = lat
+ default_zoom = 13
+ units = True
+ scrollable = False
+ map_width = 700
+ map_height = 425
+ map_template = 'gis/admin/osm.html'
+ openlayers_url = '/static/admin/js/OpenLayers.js'
+
+ def __init__(self, parent_model, admin_site):
+ self.admin_site = admin_site
+ self.parent_model = parent_model
+ self.opts = self.model._meta
+ self.has_registered_model = admin_site.is_registered(self.model)
+ overrides = copy.deepcopy(FORMFIELD_FOR_DBFIELD_DEFAULTS)
+ for k, v in self.formfield_overrides.items():
+ overrides.setdefault(k, {}).update(v)
+ self.formfield_overrides = overrides
+ if self.verbose_name is None:
+ self.verbose_name = self.model._meta.verbose_name
+ if self.verbose_name_plural is None:
+ self.verbose_name_plural = self.model._meta.verbose_name_plural
@admin.register(AP)