Start by defining a custom signal. The custom signal here is a subclass of django.dispatch.Signal . This code may be in app/signals.py .
from django.dispatch import Signal user_address_changed = Signal(providing_args=["user"])
Then make sure you send this signal when your user address is changed. Depending on how you defined User and Address , this can be done in different places. Suppose there is a view that allows users to update their Address models. This code is supposedly located in app/views.py .
from app import signals def update_address(request, *args, **kwargs):
Now you need to configure the 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']
Update
(After reading the comment, the OP explains that there is no separate view that updates the address). In this case, you can try to override User.save() to send this signal. I say "try" because I donβt know if you use your own User class or auth.User .
Manoj govindan
source share