Admin app ignores custom form settings for inline formsets for inline-edited foreign key models
|Reported by:||dan||Owned by:||nobody|
|Has patch:||yes||Needs documentation:||no|
|Needs tests:||yes||Patch needs improvement:||no|
custom form values appear to be being ignored for inline form sets in the admin app. Say if i try to eclude a field from an inline-edited form
consider a simple app: (in my case the app is called
simple, in the project
class Salad (models.Model) : name = models.TextField(max_length=100) class Ingredient (models.Model) : name = models.TextField(max_length=100) salad = models.ForeignKey(Salad) unwanted = models.TextField(max_length=200)
If i define an admin site which will allow Ingredient to be edited inline in the Salad admin, then it appears i lose the ability to customize the form. say I wish to exclude the field "unwanted" from being edited in the inline formset. I defined an admin site thusly in the app's
import reducer.simple.models as simplemodels from django.contrib import admin from django import forms from django.forms.models import inlineformset_factory class IngredientForm(forms.ModelForm): class Meta: exclude = ("unwanted") model = simplemodels.Ingredient IngredientInlineFormSet = inlineformset_factory( simplemodels.Salad, simplemodels.Ingredient, exclude = ["unwanted"], form = IngredientForm, ) class IngredientInline(admin.TabularInline): model = simplemodels.Ingredient extra = 3 formset = IngredientInlineFormSet form = IngredientForm class SaladAdmin(admin.ModelAdmin): inlines = ( IngredientInline, ) adminsite = admin.AdminSite() adminsite.register(simplemodels.Salad, SaladAdmin)
Now if i fire this site up in a development server and browse to http://localhost:8000/admin/simple/salad/add/, i will find that the "unwanted" field is still available in the admin interface, despite being excluded from the form that i have specified as the admin
there is some redundancy in my test case above; I have specified the from both in
IngredientInlineFormSet; I have specified the excluded fields both in
IngredientForm and in
IngredientInlineFormSet. However, I have made still further reduced cases where these values are specified once each and they still fail.
It's the end of a long day and I'll be away for the weekend, so I'm posting this issue here now rather than tracing any further down through the newforms admin site code, whose mysterious form rendering logic i have yet to grok. Hopefully someone wiser than I will have a look.