Skip to content

Commit 7ddcbfd

Browse files
committed
update admin
1 parent 01eeed4 commit 7ddcbfd

File tree

2 files changed

+37
-7
lines changed

2 files changed

+37
-7
lines changed

backend/proteins/admin.py

Lines changed: 34 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -99,10 +99,8 @@ class OSERInline(admin.StackedInline):
9999
]
100100

101101

102-
class StateInline(MultipleSpectraOwner, admin.StackedInline):
103-
# form = StateForm
104-
# formset = StateFormSet
105-
model = State
102+
class FluorStateInline(MultipleSpectraOwner):
103+
model = FluorState
106104
extra = 0
107105
can_delete = True
108106
show_change_link = True
@@ -115,9 +113,8 @@ class StateInline(MultipleSpectraOwner, admin.StackedInline):
115113
("ex_max", "em_max"),
116114
("ext_coeff", "qy"),
117115
("twop_ex_max", "twop_peak_gm", "twop_qy"),
118-
("pka", "maturation"),
116+
"pka",
119117
"lifetime",
120-
"bleach_links",
121118
"spectra",
122119
)
123120
},
@@ -132,13 +129,25 @@ class StateInline(MultipleSpectraOwner, admin.StackedInline):
132129
]
133130
readonly_fields = (
134131
"slug",
135-
"bleach_links",
136132
"created",
137133
"created_by",
138134
"modified",
139135
"updated_by",
140136
)
141137

138+
139+
class StateInline(FluorStateInline, admin.StackedInline):
140+
# form = StateForm
141+
# formset = StateFormSet
142+
model = State
143+
fieldsets = [
144+
*FluorStateInline.fieldsets,
145+
(None, {"fields": ("bleach_links",)}),
146+
(None, {"fields": ("maturation",)}),
147+
]
148+
149+
readonly_fields = (*FluorStateInline.readonly_fields, "bleach_links")
150+
142151
@admin.display(description="BleachMeasurements")
143152
def bleach_links(self, obj):
144153
links = []
@@ -149,6 +158,10 @@ def bleach_links(self, obj):
149158
return mark_safe(", ".join(links))
150159

151160

161+
class DyeStateInline(FluorStateInline, admin.StackedInline):
162+
model = DyeState
163+
164+
152165
class LineageInline(admin.TabularInline):
153166
model = Lineage
154167
autocomplete_fields = ("parent", "root_node")
@@ -168,8 +181,22 @@ class LightAdmin(SpectrumOwner, admin.ModelAdmin):
168181
@admin.register(Dye)
169182
class DyeAdmin(admin.ModelAdmin):
170183
model = Dye
184+
list_display = ("__str__", "created_by", "created")
171185
ordering = ("-created",)
172186
list_filter = ("created", "manufacturer")
187+
fields = (
188+
"name",
189+
"slug",
190+
"manufacturer",
191+
"default_state",
192+
"primary_reference",
193+
"created",
194+
"modified",
195+
"created_by",
196+
"updated_by",
197+
)
198+
readonly_fields = ("created", "modified")
199+
inlines = (DyeStateInline,)
173200

174201

175202
@admin.register(DyeState)

backend/proteins/models/dye.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,9 @@ class Dye(Authorable, TimeStampedModel, Product): # TODO: rename to SmallMolecu
4848
class Meta:
4949
abstract = False
5050

51+
def __str__(self) -> str:
52+
return self.name
53+
5154
def save(self, *args, **kwargs):
5255
self.slug = slugify(self.name) # Always regenerate, like Protein.save()
5356
super().save(*args, **kwargs)

0 commit comments

Comments
 (0)