Monday, December 22, 2014

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

Hi Alex,

Am 20.12.2014 um 22:47 schrieb Alex Haylock:
> Take a look at the Django signal dispatcher:
> https://docs.djangoproject.com/en/dev/topics/signals/
>
> Specifically, the 'update_fields' argument passed to the 'pre_save'
> signal should provide what you need:
>
> https://docs.djangoproject.com/en/dev/ref/signals/#django.db.models.signals.pre_save

Many thanks for your reply!

While I seem to understand signals generally, I followed Collin's
suggestion, because the ModelAdmin class already has so many readily
available customization callbacks, so that this eventually looked a bit
more straightforward to me.

Also, the big question that occurred to me when I (re-)read the signals
documentation that you linked above was this description for the
`update_fields` argument:
"The set of fields to update explicitly specified in the save()
method. None if this argument was not used in the save() call."

To be honest, I did not fully set it up to try it out, but in the
ModelAdmin source I saw that the model's save() method is plainly
called, without any explicit parameters. This would have rendered the
`update_fields` useless, and left me with no way to figure out what has
changed in the model when the pre_save signal is received, right?

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/54985876.9040805%40cafu.de.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment