[Fixed]-Extending a model in Django

1👍

if you creating the Profile instance with User it already saved in the database if you use create method. you don’t need to save seperatly.
ie the following signls is enough for saving and creating user profile instance

@receiver(post_save, sender=User)
def create_user_profile(sender, instance, created, **kwargs):
    if created:
        Profile.objects.create(user=instance)
👤Cadmus

0👍

The OneToOne relation means that you can have only one profile per user.

Modify the code to

class Profile(Entity):
   user = models.ForeignKey(User, on_delete=models.CASCADE)
👤mta194

Leave a comment