Monday, December 22, 2014

Re: ModelAdmin with inlines: How to learn if/what has changed before the models are saved?

Hi Collin,

Am 20.12.2014 um 00:18 schrieb Collin Anderson:
> save_model() happens first, then save_related() which
> calls save_formset() on each formset.
>
> It might end up being easier to save the parent model _again_, instead
> of doing something before it's saved.

Thank you very much for your reply, that helped a lot!

> _has_changed() / has_changed() may come in handy in your case.
> https://docs.djangoproject.com/en/dev/ref/forms/fields/#has-changed

In Django 1.7, it seems that _has_changed() takes several parameters
that I had not readily available, so I eventually looked this up in the
Django 1.7 source code (django/forms/forms.py), and now instead of, for
example (probably valid Django 1.8 code):

if form.fields['birthday'].has_changed(): ...

with Django 1.7 I use:

if "birthday" in form.changed_data: ...

which works very well!

Thanks again for your help!

:-)

Best regards,
Carsten

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/54985604.5040903%40cafu.de.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment