From fe840798858380a6210c678f3a5289c490651c1f Mon Sep 17 00:00:00 2001 From: Dana Lambert Date: Fri, 5 Nov 2021 16:18:47 +1300 Subject: [PATCH] Add admin autocomplete, search fields and ordering to zone field in ZoneImageSegment --- backend/right_tree/api/admin.py | 14 ++++++++++++-- backend/right_tree/api/models.py | 3 +++ 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/backend/right_tree/api/admin.py b/backend/right_tree/api/admin.py index cf5b649..bd8b267 100644 --- a/backend/right_tree/api/admin.py +++ b/backend/right_tree/api/admin.py @@ -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) diff --git a/backend/right_tree/api/models.py b/backend/right_tree/api/models.py index cbbcda0..25cf16a 100644 --- a/backend/right_tree/api/models.py +++ b/backend/right_tree/api/models.py @@ -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(