I see these nice “local flavors” for Canada, but they’re only form fields. How would I use them in my model? I can create them all as CharFields sure, but then is there a way to set the default form widget from inside the model so that when I create a ModelForm it’ll use them?
I see these nice local flavors for Canada , but they’re only form fields.
Share
No. Since validation is a form business (and not model business) you can’t define that at the model level. You’ll have to define a custom form that uses your specific FormField, and use that form.
The docs explain well how to define custom field types and widgets.
BTW: This is an answer I’d love to be proven wrong about… IMO the current state of django’s model level validation is not good enough… widgets, as in the way to visually represent the field, are form business, but the fields’ validation can be model business as well, like in your case.