From 688adfac42cdb85e64b04ec592d36c11c3872fce Mon Sep 17 00:00:00 2001 From: PCoder Date: Thu, 11 Nov 2021 23:27:43 +0530 Subject: [PATCH] Fix SpeciesRange admin listing --- app/admin.py | 14 +++++++++++++- app/models.py | 2 +- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/app/admin.py b/app/admin.py index dc9c987..3798ac4 100644 --- a/app/admin.py +++ b/app/admin.py @@ -125,6 +125,18 @@ class PeopleRangeAdmin(admin.ModelAdmin): return str(obj.range.name) +class SpeciesRangeAdmin(admin.ModelAdmin): + model = SpeciesRange + search_fields = ['scientific_name__scientific_name', 'range__range_name'] + list_display = ['scientific_name', 'range_name'] + + def scientific_name(self, obj): + return str(obj.scientific_name.scientific_name) if obj and obj.scientific_name and obj.scientific_name.scientific_name else '--' + + def range_name(self, obj): + return str(obj.range) if obj.range else '--' + + class RangeCountryAdmin(admin.ModelAdmin): model = RangeCountry search_fields = ['range__range_name', 'country__short_name'] @@ -178,7 +190,7 @@ admin.site.register(TaxaPeople) admin.site.register(ScalesPeople) admin.site.register(Species, SpeciesAdmin) admin.site.register(PeopleFunction) -admin.site.register(SpeciesRange) +admin.site.register(SpeciesRange, SpeciesRangeAdmin) admin.site.register(RangesPeople, PeopleRangeAdmin) admin.site.register(TaxonRange, TaxonRangeAdmin) admin.site.register(PeopleResource) diff --git a/app/models.py b/app/models.py index e0f1bf6..e6599c2 100644 --- a/app/models.py +++ b/app/models.py @@ -648,7 +648,7 @@ class SpeciesRange(models.Model): source_url = models.TextField(blank=True, null=True) def __str__(self): - return self.scientific_name.scientific_name + return self.scientific_name.scientific_name if self and self.scientific_name else ' -- ' class PeopleRange(models.Model):