ModelForm requires fields set to null=True, blank=True ?
|Reported by:||Owned by:||nobody|
|Has patch:||no||Needs documentation:||no|
|Needs tests:||no||Patch needs improvement:||no|
I have a model which goes like this:
class Announcement(models.Model): """ Data model for announcements """ language = models.ForeignKey(Language) regions = models.ManyToManyField(Region) countries = models.ManyToManyField(Country, null = True, blank = True) ...
and an Announcement form which extends ModelForm:
model = Announcement
exclude = ('time_trashed',)
Now I pre-select a single Country from user profile, as a convenience, using form.fieldscountries?.initial when I display the form. When a user deselect that Country in the form, and tries to save it, form.save() fails without an error. When I select some countr(ies), form.save() works.