I'm wondering whether it's possible to selectively suppress a Django signal (such as post_save or post_init) on object creation, or, alternatively, send it certain parameters.
What I have is a User object, which can be created in many different ways and places in my code. So to automatically assign a custom Profile object to each User, I use the post_save signal. However, in one specific case, there is extra information that I want to bind to the created Profile object. Passing it as arguments to the post_save signal would be great, but it doesn't look possible.
The other option is to manually create the Profile object, but then I need to that after the User is saved, otherwise the Profile cannot be bound to a User instance. Saving the User instance, however, results in another Profile being created via the function called by the signal.
And I can't just get the just-created Profile object, since that results in a 'Profile' object is unsubscriptable error. Any advice?
Update:
Here is an example of a possible situation:
def createUserProfile(sender, instance, created, **kwargs):
if created:
profile, created = Profile.objects.get_or_create(user=instance)
if extra_param:
profile.extra_param = extra_param
profile.save()
post_save.connect(createUserProfile, sender=User)
def signup(request):
...
extra_param = 'param'
user.save()
How do I get the variable extra_param in the signup method to the createUserProfile method, where it is to be stored as part of the Profile object?