diff options
Diffstat (limited to 'app')
-rw-r--r-- | app/birds/admin.py | 34 | ||||
-rw-r--r-- | app/birds/models.py | 9 |
2 files changed, 39 insertions, 4 deletions
diff --git a/app/birds/admin.py b/app/birds/admin.py index 8c09b7b..1cc905d 100644 --- a/app/birds/admin.py +++ b/app/birds/admin.py @@ -1,7 +1,15 @@ from django.contrib import admin from django.contrib.gis.admin import OSMGeoAdmin from birds.models import BirdSighting, BirdAudio, BirdClass, Bird +from django.contrib.gis.geos import GEOSGeometry, Point +def convertll(lat, lon): + pnt = GEOSGeometry('POINT({0} {1})'.format(lon, lat), srid=4326) + pnt.transform(3857) + return pnt.y, pnt.x + + +lat, lon = convertll(29.658057, -84.867797) class BirdClassAdmin(admin.ModelAdmin): list_display = ('common_name', 'scientific_name',) @@ -15,12 +23,32 @@ class BirdAdmin(admin.ModelAdmin): class BirdSightingAdmin(OSMGeoAdmin): + list_display = ('bird', 'location') list_filter = ('location',) + fieldsets = ( + ('Sighting', { + 'fields': ( + 'bird', + 'point', + 'date', + 'image', + 'seen_by' + ), + 'classes': ( + 'show', + 'extrapretty', + 'wide' + ) + } + ), + ) # options for OSM map Using custom ESRI topo map - default_lon = -9285175 - default_lat = 4025046 - default_zoom = 10 + #default_lon = -9285175 + #default_lat = 4025046 + default_lon = lon + default_lat = lat + default_zoom = 13 units = True scrollable = False map_width = 700 diff --git a/app/birds/models.py b/app/birds/models.py index 2ba9451..453e3fd 100644 --- a/app/birds/models.py +++ b/app/birds/models.py @@ -73,7 +73,7 @@ class BirdAudio(models.Model): class BirdSighting(models.Model): bird = models.ForeignKey(Bird) point = models.PointField() - location = models.ForeignKey(Location) + location = models.ForeignKey(Location, blank=True) date = models.DateTimeField('Date', default=timezone.now) image = models.FileField(upload_to=get_upload_path, null=True, blank=True) seen_by = models.ManyToManyField(User) @@ -104,3 +104,10 @@ class BirdSighting(models.Model): return self.point.y def __str__(self): return self.bird.common_name + + def save(self): + try: + self.location = Location.objects.filter(geometry__contains=self.point).get() + except Location.DoesNotExist: + raise forms.ValidationError("There is no location associated with that point, add it: %sadmin/locations/location/add/" % (settings.BASE_URL)) + super(BirdSighting, self).save() |