Replies: 1 comment
-
|
You don’t need to fully override
Why your merge-by-title approach hits a wall
A practical “fieldset patch” approach1) In your base admin, define your canonical fieldsetsclass ProductAdmin(PolymorphicParentModelAdmin):
base_fieldsets = (
("Basics", {"fields": ("name", "sku", "price")}),
("Inventory", {"fields": ("in_stock", "qty")}),
("Meta", {"fields": ("created_at", "updated_at")}),
)2) In each child admin, declare injection rulesUse a structure like:
Example: class PhoneTabletsAdmin(PolymorphicChildModelAdmin):
fieldset_injections = {
"Basics": {"after": {"sku": ("screen_size", "ram_storage")}},
"Inventory": {"append": ("battery_capacity",)},
}3) Apply those rules in a helper used by
|
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
I have a model with extra fields but I would like to show these extra fields inside already existing fieldsets from the form base class.
I was able to do it with something like
I can only override one section here because it's based on the
extra_fieldset_titleThis doesn't control where the fields end up in the fieldsets.
If I use
extra_fieldset_titlewith the same name, well I just get 2 fieldsets with the same names.For a case like this, should I just fully override base_fieldsets for each subclasses? Which is kind of annoying.
Beta Was this translation helpful? Give feedback.
All reactions