Add admin autocomplete, search fields and ordering to zone field in ZoneImageSegment

This commit is contained in:
Dana Lambert 2021-11-05 16:18:47 +13:00
parent de0b5abb7b
commit fe84079885
2 changed files with 15 additions and 2 deletions

View file

@ -1,6 +1,16 @@
from django.contrib import admin
import right_tree.api.models as models
class ZoneAdmin(admin.ModelAdmin):
ordering = ['name', 'variant', 'refined_variant', 'id']
search_fields = ['name', 'variant', 'refined_variant', 'id']
class ZoneImageSegmentAdmin(admin.ModelAdmin):
autocomplete_fields = ['zone']
admin.site.register(models.Plant)
admin.site.register(models.SoilOrder)
admin.site.register(models.SoilLayer)
@ -10,5 +20,5 @@ admin.site.register(models.EcologicalDistrictLayer)
admin.site.register(models.ToleranceLevel)
admin.site.register(models.HabitatImage)
admin.site.register(models.Habitat)
admin.site.register(models.Zone)
admin.site.register(models.ZoneImageSegment)
admin.site.register(models.Zone, ZoneAdmin)
admin.site.register(models.ZoneImageSegment, ZoneImageSegmentAdmin)

View file

@ -82,6 +82,9 @@ class Zone(models.Model):
variant_str = f"({self.variant}{refined_variant_str})" if self.variant is not None else ""
return f"{self.name} {variant_str}"
class Meta:
ordering = ['name', 'variant', 'refined_variant', 'id']
class ZoneImageSegment(models.Model):
zone = models.ForeignKey(