It’s a bit odd but I would like to define some properties of a form field like its widget or class from the model definition. I know it is easy from the form but I’d like to know if it’s possible from the model. I’m not sure but I think I remember having seen something like that some day.
Share
Well, you can create your own subclasses of model fields and redefine their
formfieldmethod to add the properties you want but it might not be worth the effors as you’ll be overriding . That’s hour call, however.Anyway, in case you decide to try this, make sure to follow these two sections from the documentation:
ModelForms and custom fields
and
Specifying the form field for a model field as the default implementation of
Field.formfielddoes some important stuff you generally don’t want to omit.