2π
β
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:
class MemberAdminInlineForm(forms.ModelForm):
def clean_last_name(self):
if hasattr(self, "instance"):
if self.instance.first_name == "Joe":
return self.instance.last_name
return self.cleaned_data["last_name"].
class MemberAdminInline(admin.TabularInline):
model = Member
fields = ("first_name", "last_name")
readonly_fields = ("first_name", )
form = MemberAdminInlineForm
π€Zaar Hai
Source:stackexchange.com