Note that there are some explanatory texts on larger screens.

plurals
  1. POIs it possible to selectively suppress a post_save (or other) signal in Django?
    primarykey
    data
    text
    <p>I'm wondering whether it's possible to selectively suppress a Django signal (such as <code>post_save</code> or <code>post_init</code>) on object creation, or, alternatively, send it certain parameters.</p> <p>What I have is a <code>User</code> object, which can be created in many different ways and places in my code. So to automatically assign a custom <code>Profile</code> object to each <code>User</code>, I use the <code>post_save</code> signal. However, in one specific case, there is extra information that I want to bind to the created <code>Profile</code> object. Passing it as arguments to the <code>post_save</code> signal would be great, but it doesn't look possible. </p> <p>The other option is to manually create the <code>Profile</code> object, but then I need to that after the <code>User</code> is saved, otherwise the <code>Profile</code> cannot be bound to a <code>User</code> instance. Saving the <code>User</code> instance, however, results in another <code>Profile</code> being created via the function called by the signal.</p> <p>And I can't just get the just-created <code>Profile</code> object, since that results in a <code>'Profile' object is unsubscriptable</code> error. Any advice?</p> <p><strong>Update:</strong></p> <p>Here is an example of a possible situation:</p> <pre><code>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() </code></pre> <p>How do I get the variable <code>extra_param</code> in the <code>signup</code> method to the createUserProfile method, where it is to be stored as part of the <code>Profile</code> object?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload