Opened 11 years ago

Closed 11 years ago

Last modified 11 years ago

#21474 closed Uncategorized (needsinfo)

ModelForm resets field when field not in data

Reported by: Mike Wyatt (wyatt.mike@… Owned by: nobody
Component: Forms Version: dev
Severity: Normal Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

After reading "Don't assume that missing fields from POST data are equal to an empty string value" (https://groups.google.com/forum/#!topic/django-developers/w8UKCLjOMpg), I still don't get how something like:

profile = Profile.objects.create(first_name='Tai', last_name='Lee',
address='Sydney')
form = ProfileForm({}, instance=profile)
if form.is_valid():
    form.save()

clearing the existing fields on the form could be seen as intuitive. Or how the Django co-creator Adrian Holovaty advises against using ModelForms, something included in his framework.

My case is I've a published_at field on a model, and when the form is submitted, that field is reset. I would expect it to stay the same.

Sure, there's the fields and exclude properties of the Meta class, but things can still be mass-assigned via POST. Maybe take a page from other frameworks that worked around this issue years ago?

I should mention this issue stems from using django-crispy-forms, where I've never really had to use those properties on the form's meta class, where one can easily design a form as they want, and are not limited to tables or unordered lists.

Change History (2)

comment:1 by Tim Graham, 11 years ago

Resolution: needsinfo
Status: newclosed

Feel free to revive the discussion on the mailing list if you'd like to propose a change as that will get more eyeballs, but as it is, I see several core developers on the mailing list who are against the proposal in its current form. I don't want you to think I'm dismissing you too quickly, but I see more of a general complaint here than an actionable proposal.

comment:2 by Aymeric Augustin, 11 years ago

By the way, here are two tips about our community's values:

  • Core devs are strongly attached to their freedom of expressing individual opinions, especially when they contradict practices encouraged by Django's implementation or documentation.
  • Bad-mouthing the creator of Django isn't going to gain you any goodwill or increase your credibility.
Note: See TracTickets for help on using tickets.
Back to Top