I have the form in Django admin with tabular inline:
class MemberAdminInline(admin.TabularInline):
model = Member
fields = ("first_name", "last_name")
readonly_fields = ("first_name", )
class GroupAdmin(admin.ModelAdmin):
model = Group
fields = ("name", "description")
inlines = [MemberAdminInline]
I would like to display Member’s last_name conditionally. I.e.
"If first_name = "Joe": don't display show field for last_name".
Its important to really not to display field and not hide it (Using JS for example),
because in my real-work scenario in certain cases this field can contain a binary data which gets breaked when passed through form.
I.e.
I want last_name to be editable through admin only for certain first_names.
I’ve tried provide a custom form for inline and conditionally remove field from there, or dynamically include field in list of readonly_fields at various stages, but Django still always tried to find the field I want to hide field.
Django 1.3.1
It seems like Django calculates list of fields for formset at inline creation time and then formset insists on these fields to exist.
So the only ways to overcome this that I’ve found is to actually ignore saved value when needed: