Skip to content

Commit

Permalink
SCKAN-275 feat: Update admin page names
Browse files Browse the repository at this point in the history
  • Loading branch information
afonsobspinto committed Mar 21, 2024
1 parent fadd3aa commit f40300c
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 22 deletions.
30 changes: 12 additions & 18 deletions backend/composer/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
Tag,
Via,
FunctionalCircuitRole,
ProjectionPhenotype, Destination, Synonym, AnatomicalEntityMeta, Layer, Region, AnatomicalEntityIntersection,
ProjectionPhenotype, Destination, Synonym, AnatomicalEntityMeta, Layer, Region,
AnatomicalEntityIntersection,
AnatomicalEntity
)

Expand Down Expand Up @@ -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")
Expand All @@ -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
Expand Down
10 changes: 6 additions & 4 deletions backend/composer/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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:
Expand Down

0 comments on commit f40300c

Please sign in to comment.