Opened 7 years ago

Closed 7 years ago

#6525 closed (worksforme)

ModelForm requires fields set to null=True, blank=True ?

Reported by: pat.j.anderson@… Owned by: nobody
Component: Forms Version: master
Severity: Keywords: ModelForm
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:

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.

Change History (1)

comment:1 Changed 7 years ago by mattmcc

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Resolution set to worksforme
  • Status changed from new to closed

I can't reproduce this. I suggest bringing the matter up on the django-users mailing list, or the #django IRC channel.

Note: See TracTickets for help on using tickets.
Back to Top