I am trying to create a custom signal for when the field auth_user.is_active becomes 1. I looked at Django’s docs on signals, but was having trouble understanding how to implement custom signals.
When a user account becomes active, I want to execute the following function:
def new_user(sender, **kwargs)
profile = User.objects.get(id=user_id).get_profile()
return RecentActivity(content_object=profile, event_type=1, timestamp=datetime.datetime.now())
How would I do this. And also, what is the advantage of using signals over just doing the database insert directly? Thank you.
If you want to do something when the field is changing, you can use the approach suggested by Josh, which is essentially to override the
__init__method.Signals are generally used to communicate between apps. For example auth app sends
user_logged_insignal. So if you want to do something when user is logging in, you just handle this signal, no need to patch the app.