In django admin, there are fields I'd like to require if a model is being edited standalone. If it is inline, I don't want them to be required. Is there a way to do this?
views:
118answers:
1
+3
A:
Sure. Just define a custom form, with your required field overridden to set required=True, and use it in your admin class.
class MyForm(forms.ModelForm):
required_field = forms.CharField(required=True)
class Meta:
model = MyModel
class MyAdmin(admin.ModelAdmin):
form = MyForm
class MyInlineAdmin(admin.ModelAdmin):
model = MyModel
So here MyAdmin is using the overridden form, but MyInlineAdmin isn't.
Daniel Roseman
2009-06-30 06:45:57
Thanks very much
Mitch
2009-07-01 17:00:00