I have a model that inherits from another model (not abstract) I have a ModelForm for the 开发者_运维技巧inherited model, but i dont want to display any of the fields from the base model. What is the best way to accomplish this other than explicitly manually adding each field to the exclude list?
Use Meta.exclude
class ChildForm(BaseModelForm):
class Meta:
model = Amodel
exclude = ('parentfield1', 'parentfield2')
I'd personally go with setting the include fields to those of the current class so you don't have to reference (potentially) another file to see the fields. Also allows the parent to be updated without affecting your form.
You could potentially examine the fields within the __dict__
and see if they belong to a parent, but I honestly don't think it'd be worth it. In short, there is no easy way.
精彩评论