[Answered ]-Is it possible set field size on Model?


No, field size cannot be defined on the model. The issue you describe with exclude not working on the child when the field is defined on the parent is actually an open bug in Django. In a sense, your frustration is warranted, but unfortunately, you don’t have many options.

You might want to try a mix-in:

class MyFieldMixIn(forms.ModelForm):
    my_field = forms.CharField(label = 'Nome',widget=forms.TextInput(attrs={'size':'30','maxlength':'100'}))

class ParentForm(forms.ModelForm):
    # Common functionality, fields, etc. here

class ReplacementParentForm(ParentForm, MyFieldMixIn):

class ChildForm(ParentForm):
    # Child-specific stuff here

Then instead of using the parent form you use the replacement, so you get that field only on that form.

Leave a comment