5
Try overriding the ModelAdmin.save_model
method. I think it has hooks for all the information you require.
The change
variable lets you distinguish between a user adding or changing the model instance.
form.changed_data
gives you a list of the names of the fields which have changed, which lets you determine whether or not to send the email.
Finally request.user
identifies the user which made the changes.
1
You need django.db.models.signals.post_save
signal. It is sanding after the model has been saved.
def my_callback(sender, **kwargs):
# Your specific logic here
pass
post_syncdb.connect(my_callback, sender=yourapp.models.TheModel)
Arguments sent with this signal:
- sender:
The model class. - instance:
The actual instance being saved. - created
A boolean; True if a new record was created. - raw:
A boolean; True if the model is saved exactly as presented (i.e. when loading a fixture). One should not query/modify other records in the database as the database might not be in a consistent state yet.
So you need only callback and sender.
- [Django]-Why doesn't a django sqlite3 database work the same on one machine vs the other?
- [Django]-Get local system time in Django
- [Django]-Is client side validation nessesary in Django?
Source:stackexchange.com