diff --git a/backend/composer/admin.py b/backend/composer/admin.py index 8ee879a3..e6c09687 100644 --- a/backend/composer/admin.py +++ b/backend/composer/admin.py @@ -18,7 +18,8 @@ Tag, Via, FunctionalCircuitRole, - ProjectionPhenotype, Destination, Synonym, AnatomicalEntityMeta, Layer, Region, AnatomicalEntityIntersection, + ProjectionPhenotype, Destination, Synonym, AnatomicalEntityMeta, Layer, Region, + AnatomicalEntityIntersection, AnatomicalEntity ) @@ -94,6 +95,16 @@ class SynonymInline(admin.TabularInline): extra = 1 +class AnatomicalEntityAdmin(admin.ModelAdmin): + search_fields = ('simple_entity__name', 'region_layer__layer__name', 'region_layer__region__name') + + def get_model_perms(self, request): + """ + Return empty dict to hide the model from admin index. + """ + return {} + + class AnatomicalEntityMetaAdmin(admin.ModelAdmin): list_display = ("name", "ontology_uri") list_display_links = ("name", "ontology_uri") @@ -117,23 +128,6 @@ class AnatomicalEntityIntersectionAdmin(admin.ModelAdmin): raw_id_fields = ('layer', 'region',) -class AnatomicalEntityAdmin(admin.ModelAdmin): - raw_id_fields = ('simple_entity', 'region_layer') - search_fields = ('simple_entity__name', 'region_layer__layer__name', 'region_layer__region__name') - list_display = ('simple_entity', 'display_region_layer') - inlines = [SynonymInline] - - def display_region_layer(self, obj): - if obj.region_layer: - layer_name = obj.region_layer.layer.name if obj.region_layer.layer else "No Layer" - region_name = obj.region_layer.region.name if obj.region_layer.region else "No Region" - return f"{region_name} / {layer_name}" - return "-" - - display_region_layer.short_description = 'Region Layer' - display_region_layer.admin_order_field = 'region_layer__layer__name' - - class ViaInline(SortableStackedInline): model = Via extra = 0 diff --git a/backend/composer/models.py b/backend/composer/models.py index ee377951..93879244 100644 --- a/backend/composer/models.py +++ b/backend/composer/models.py @@ -233,7 +233,8 @@ def __str__(self): class Meta: ordering = ["name"] - verbose_name_plural = "Anatomical Entities Meta" + verbose_name = "Anatomical Entity" + verbose_name_plural = "Anatomical Entities" class Layer(AnatomicalEntityMeta): @@ -249,14 +250,15 @@ class AnatomicalEntityIntersection(models.Model): layer = models.ForeignKey(Layer, on_delete=models.CASCADE) region = models.ForeignKey(Region, on_delete=models.CASCADE) + class Meta: + verbose_name = "Region/Layer Combination" + verbose_name_plural = "Region/Layer Combinations" + class AnatomicalEntity(models.Model): simple_entity = models.OneToOneField(AnatomicalEntityMeta, on_delete=models.CASCADE, null=True, blank=True) region_layer = models.ForeignKey(AnatomicalEntityIntersection, on_delete=models.CASCADE, null=True) - class Meta: - verbose_name_plural = "Anatomical Entities" - @property def name(self): if self.simple_entity: