Opened 18 years ago
Closed 18 years ago
#6525 closed (worksforme)
ModelForm requires fields set to null=True, blank=True ?
| Reported by: | Owned by: | nobody | |
|---|---|---|---|
| Component: | Forms | Version: | dev | 
| Severity: | Keywords: | ModelForm | |
| Cc: | Triage Stage: | Unreviewed | |
| Has patch: | no | Needs documentation: | no | 
| Needs tests: | no | Patch needs improvement: | no | 
| Easy pickings: | no | UI/UX: | no | 
Description
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:
{{
class AnnouncementForm(forms.ModelForm):
    
class Meta:
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.
I can't reproduce this. I suggest bringing the matter up on the django-users mailing list, or the #django IRC channel.