Start by defining a custom signal. A custom signal here is a sub class of django.dispatch.Signal
. This code can live in app/signals.py
.
from django.dispatch import Signal
user_address_changed = Signal(providing_args=["user"])
Next, make sure you send this signal when your user's address is changed. Depending on how you have defined User
and Address
this can be done in different places. Let us assume that there is a view that lets users update their Address
models. This code is presumably in app/views.py
.
from app import signals
def update_address(request, *args, **kwargs):
# all the changes go well.
signals.user_address_changed.send(sender=None, user=request.user)
# Render to template etc.
Now you need to set up a receiver for this signal.
from app.signals import user_address_changed
def handle_user_address_change(sender, **kwargs):
"""Trap the signal and do whatever is needed"""
user = kwargs['user']
# Write to log, update db, send mail etc.
user_address_changed.connect(handle_user_address_change)
Update
(After reading comment; the OP explains that there is no separate view that updates address) In that case you can try to override User.save()
to send out this signal. I say "try" because I do not know if you are using your own User
class or auth.User
.