Skip to content Skip to sidebar Skip to footer

How To Insert Default Value In Database Table When User Account Is Created In Django?

I am using postgre database have 10 channel in my database. This is my models with channelId and userId as foreign key: class Count(models.Model): userId = models.ForeignKey(Us

Solution 1:

There are 2 possible solutions:

  1. You can use signals. Create a post_save signal for your AUTH_USER_MODEL. It is usually used to execute some logic just after a model’s save() method is called. In that signal function write logic for creating Count for all channels and rate. You can get id for ATUTH_USER_MODEL from post_signal.

    Refer https://docs.djangoproject.com/en/2.2/topics/signals/

  2. Create a logic for registering user for your AUTH_USER_MODEL and after user creation, create Count for all channels and rate.


Post a Comment for "How To Insert Default Value In Database Table When User Account Is Created In Django?"