FAQ
From 1.2 release notes (backward incompatible change):
"Much of the validation work for ModelForms has been moved down to the
model level. As a result, the first time you call
ModelForm.is_valid(), access ModelForm.errors or otherwise trigger
form validation, your model will be cleaned in-place. This conversion
used to happen when the model was saved. If you need an unmodified
instance of your model, you should pass a copy to the ModelForm
constructor.

I am migrating from 1.1 to 1.3. Some of my code rely on model not
being cleaned in place. As some fields become read only and should
not be changed. This 1.2 functionality makes those field empty. Also I
save the model and not the form in these cases.

So as per documentation, to get around it, I need to pass a copy of
model to form. What is the best way to get a copy of model:
1) use deepcopy?
2) get the object twice from db? (slow as more db access)

Any downsides to using deepcopy? Anything I need to be careful about?

Anyone else also had this issue and any suggestions.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to django-users+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

Search Discussions

  • Kurtis Mullins at Jun 12, 2012 at 2:29 pm
    I'm not sure if I understand the problem correctly, but I think this might
    be what you're looking to do.

    In your ModelForm, simply exclude the fields you don't want or explicitly
    include only the fields you do want to use. Those are both under the
    ModelForm's Meta class.

    e.g.

    # Include only these fields
    class Meta:
    fields = ('fieldA', 'fieldB', 'fieldD')

    # Or Exclude a field
    class Meta:
    exclude = ('fieldC',)

    https://docs.djangoproject.com/en/dev/topics/forms/modelforms/#using-a-subset-of-fields-on-the-form
    On Sat, Jun 9, 2012 at 4:54 PM, ydjango wrote:

    From 1.2 release notes (backward incompatible change):
    "Much of the validation work for ModelForms has been moved down to the
    model level. As a result, the first time you call
    ModelForm.is_valid(), access ModelForm.errors or otherwise trigger
    form validation, your model will be cleaned in-place. This conversion
    used to happen when the model was saved. If you need an unmodified
    instance of your model, you should pass a copy to the ModelForm
    constructor.

    I am migrating from 1.1 to 1.3. Some of my code rely on model not
    being cleaned in place. As some fields become read only and should
    not be changed. This 1.2 functionality makes those field empty. Also I
    save the model and not the form in these cases.

    So as per documentation, to get around it, I need to pass a copy of
    model to form. What is the best way to get a copy of model:
    1) use deepcopy?
    2) get the object twice from db? (slow as more db access)

    Any downsides to using deepcopy? Anything I need to be careful about?

    Anyone else also had this issue and any suggestions.

    --
    You received this message because you are subscribed to the Google Groups
    "Django users" group.
    To post to this group, send email to django-users@googlegroups.com.
    To unsubscribe from this group, send email to
    django-users+unsubscribe@googlegroups.com.
    For more options, visit this group at
    http://groups.google.com/group/django-users?hl=en.
    --
    You received this message because you are subscribed to the Google Groups "Django users" group.
    To post to this group, send email to django-users@googlegroups.com.
    To unsubscribe from this group, send email to django-users+unsubscribe@googlegroups.com.
    For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupdjango-users @
categoriesdjango, python
postedJun 9, '12 at 8:54p
activeJun 12, '12 at 2:29p
posts2
users2
websitedjangoproject.com

2 users in discussion

Kurtis Mullins: 1 post Ydjango: 1 post

People

Translate

site design / logo © 2022 Grokbase