How to pass kwargs from save to post_save signal

Built-in signals are sent by Django, so you can’t control their kwargs.

You can:

  1. Define and send your own signals.
  2. Store additional info in model instance. Like this

    def save(self, commit=True):
        user = super(CustomFormThing, self).save(commit=False)
        #set some other attrs on user here ...
        user._some="some"
        user._other="other"
        if commit:
            user.save()
    
        return user
    
    @receiver(post_save, sender=User)
    def create_profile(sender, instance, created, **kwargs):
        some_id = getattr(instance, '_some', None)
        other_id = getattr(instance, '_other', None)
    
        if created:
            #do something with the kwargs above...
    

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)