#21474: ModelForm resets field when field not in data
------------------------------------------+--------------------
     Reporter:  Mike Wyatt (wyatt.mike@…  |      Owner:  nobody
         Type:  Uncategorized             |     Status:  new
    Component:  Forms                     |    Version:  master
     Severity:  Normal                    |   Keywords:
 Triage Stage:  Unreviewed                |  Has patch:  0
Easy pickings:  0                         |      UI/UX:  0
------------------------------------------+--------------------
 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.

-- 
Ticket URL: <https://code.djangoproject.com/ticket/21474>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-updates+unsubscr...@googlegroups.com.
To post to this group, send email to django-updates@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/076.c5ec396f6443f42db183a708bf5d8823%40djangoproject.com.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to