From 91c284b00174f1f11b1bec6fec633dadb9f40dd1 Mon Sep 17 00:00:00 2001 From: luxagraf Date: Sat, 9 Jun 2018 13:59:23 -0500 Subject: added a have_seen column to admin for aps --- app/sightings/admin.py | 11 +++++++++-- app/sightings/models.py | 7 +++++++ 2 files changed, 16 insertions(+), 2 deletions(-) (limited to 'app/sightings') diff --git a/app/sightings/admin.py b/app/sightings/admin.py index 03aaa83..5d51941 100644 --- a/app/sightings/admin.py +++ b/app/sightings/admin.py @@ -28,7 +28,8 @@ class APClassAdmin(admin.ModelAdmin): 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 + code straight from Django and it may change, but unless GeoDjango + adds a Mixin, this will have to do. """ model = Sighting extra = 1 @@ -64,14 +65,20 @@ class APAdmin(admin.ModelAdmin): inlines = [ SightingInline, ] - list_display = ('pk', 'common_name', 'scientific_name', 'kind', 'code', 'apclass') + list_display = ('common_name', 'have_seen', 'scientific_name', 'kind', 'code', 'apclass') list_filter = ('apclass__kind', 'apclass') search_fields = ['common_name', 'scientific_name'] + def have_seen(self, obj): + return obj.seen + have_seen.admin_order_field = 'seen' + have_seen.boolean = True + class Media: js = ('image-loader.js', 'next-prev-links.js') + @admin.register(Sighting) class SightingAdmin(OSMGeoAdmin): form = SightingsForm diff --git a/app/sightings/models.py b/app/sightings/models.py index b8d7c6f..7368bd4 100644 --- a/app/sightings/models.py +++ b/app/sightings/models.py @@ -93,6 +93,13 @@ class AP(models.Model): def get_absolute_url(self): return reverse("sightings:detail", kwargs={"slug": self.slug}) + @property + def seen(self): + if self.sighting_set.all(): + return True + else: + return False + def kind(self): return self.apclass.kind -- cgit v1.2.3-70-g09d2