1 2 3 4 5 6 7 8 9 10 11 | # SIGNALS AND LISTENERS
from django.contrib.auth.models import User
from django.db.models import signals
from django.dispatch import dispatcher
# User
def user_post_save(sender, instance, signal, *args, **kwargs):
# Creates user profile
profile, new = UserProfile.objects.get_or_create(user=instance)
dispatcher.connect(user_post_save, signal=signals.post_save, sender=User)
|
More like this
- Little middleware that create a facebook user by marinho 5 years, 5 months ago
- Mobilize your Django site by stevena0 4 years, 1 month ago
- SectionedForm by marinho 4 years, 11 months ago
- convenience parent class for UserProfile model by willhardy 4 years ago
- Improved User Admin by gregb 3 years ago
Comments
This is no longer valid as the way dispatcher works has been updated.
Any shot at an update?
#
For Django 1.0:
#
For Django 1.3, using the new
@receiverdecorator:#
Hello, was playing around with signals and came across an issue. Was able to use the receiver decorator approach from Ori when using the built in signals (i.e. post_save, etc.) put when I tried to use that approach with a custom signal it does not work.
I confirmed that the custom signal works if I use the approach
custom_signal.connect(custom_receiver)
and all works. but
@receiver(custom_receiver, sender=MyModel) def signal_receiver(sender, **kwargs) print 'in signal_receiver'
This does not work, does the decorator approach not work with custom signals?
Thanks
#