Fix for __str__ returned non-string error
This commit is contained in:
parent
aa65b9c9cd
commit
6f9ca6961c
2 changed files with 28 additions and 9 deletions
27
app/admin.py
27
app/admin.py
|
@ -99,6 +99,25 @@ class RangeNameTranslationAdmin(admin.ModelAdmin):
|
|||
search_fields = ['range_name_translation']
|
||||
|
||||
|
||||
class PeopleRangeAdmin(admin.ModelAdmin):
|
||||
model = Range
|
||||
list_display = ['person', 'range_name', ]
|
||||
|
||||
def range_name(self, obj):
|
||||
return str(obj.range.name)
|
||||
|
||||
|
||||
class RangeCountryAdmin(admin.ModelAdmin):
|
||||
model = RangeCountry
|
||||
search_fields = ['range__range_name', 'country__short_name']
|
||||
list_display = ['range_name', 'country_name']
|
||||
|
||||
def range_name(self, obj):
|
||||
return str(obj.range.range_name)
|
||||
|
||||
def country_name(self, obj):
|
||||
return str(obj.country.short_name) if obj.country else 'None'
|
||||
|
||||
|
||||
# Register your models here.
|
||||
admin.site.register(Person, PersonAdmin)
|
||||
|
@ -136,13 +155,13 @@ admin.site.register(ImportGeom210915)
|
|||
admin.site.register(Peak, PeaksAdmin)
|
||||
admin.site.register(Search, SearchAdmin)
|
||||
admin.site.register(TaxaPeople)
|
||||
admin.site.register(RangesPeople)
|
||||
admin.site.register(ResourcesPeople)
|
||||
# admin.site.register(RangesPeople)
|
||||
# admin.site.register(ResourcesPeople)
|
||||
admin.site.register(ScalesPeople)
|
||||
admin.site.register(Species, SpeciesAdmin)
|
||||
admin.site.register(PeopleFunction)
|
||||
admin.site.register(SpeciesRange)
|
||||
admin.site.register(PeopleRange)
|
||||
admin.site.register(RangesPeople, PeopleRangeAdmin)
|
||||
admin.site.register(TaxonRange, TaxonRangeAdmin)
|
||||
admin.site.register(PeopleResource)
|
||||
admin.site.register(RangeCountry)
|
||||
admin.site.register(RangeCountry, RangeCountryAdmin)
|
||||
|
|
|
@ -119,7 +119,7 @@ class Range(models.Model):
|
|||
db_table = 'range'
|
||||
|
||||
def __str__(self):
|
||||
return self.name
|
||||
return self.range_name if self else '--'
|
||||
|
||||
def dict(self):
|
||||
return {
|
||||
|
@ -210,7 +210,7 @@ class Country(models.Model):
|
|||
iso2 = models.TextField(blank=True, null=True)
|
||||
|
||||
def __str__(self):
|
||||
return self.formal_name
|
||||
return self.short_name if self else '--'
|
||||
|
||||
|
||||
class GMBA_SpeciesGroup(models.Model):
|
||||
|
@ -657,7 +657,7 @@ class PeopleRange(models.Model):
|
|||
range = models.ForeignKey(Range, models.DO_NOTHING, blank=True, null=True)
|
||||
|
||||
def __str__(self):
|
||||
return self.person.full_name
|
||||
return str(self.id)
|
||||
|
||||
|
||||
class TaxonRange(models.Model):
|
||||
|
@ -684,7 +684,7 @@ class PeopleResource(models.Model):
|
|||
role = models.TextField(blank=True, null=True)
|
||||
|
||||
def __str__(self):
|
||||
return self.person.full_name
|
||||
return self.person.full_name if self.person else ' -- '
|
||||
|
||||
|
||||
class RangeCountry(models.Model):
|
||||
|
@ -693,4 +693,4 @@ class RangeCountry(models.Model):
|
|||
country = models.ForeignKey(Country, models.DO_NOTHING, blank=True, null=True)
|
||||
|
||||
def __str__(self):
|
||||
return self.range.name
|
||||
return '%s --- %s' % (self.range.range_name if self.range else 'None', self.country.short_name if self.country else 'None')
|
||||
|
|
Loading…
Reference in a new issue