from django.db import models
from django.contrib.auth.models import User


class Profile(models.Model):
    user = models.OneToOneField(User)

    def __str__(self):
        return self.user.get_full_name() or self.user.username

from django.db import models
from django.db.models.signals import post_save
from django.contrib.auth.models import User


class Profile(models.Model):
    user = models.OneToOneField(User)

    def __str__(self):
        return self.user.get_full_name() or self.user.username


def create_user_profile(sender, instance, created, **kwargs):
    if created:
        Profile.objects.create(user=instance)


post_save.connect(create_user_profile, sender=User)
Create profile if user is created
Create profile if user is created

  from django.db import models
+ from django.db.models.signals import post_save
  from django.contrib.auth.models import User
  
  
  class Profile(models.Model):
      user = models.OneToOneField(User)
  
      def __str__(self):
          return self.user.get_full_name() or self.user.username
  
+ 
+ def create_user_profile(sender, instance, created, **kwargs):
+     if created:
+         Profile.objects.create(user=instance)
+ 
+ 
+ post_save.connect(create_user_profile, sender=User)
Create profile if user is created
## Code Before:
from django.db import models
from django.contrib.auth.models import User


class Profile(models.Model):
    user = models.OneToOneField(User)

    def __str__(self):
        return self.user.get_full_name() or self.user.username

## Instruction:
Create profile if user is created
## Code After:
from django.db import models
from django.db.models.signals import post_save
from django.contrib.auth.models import User


class Profile(models.Model):
    user = models.OneToOneField(User)

    def __str__(self):
        return self.user.get_full_name() or self.user.username


def create_user_profile(sender, instance, created, **kwargs):
    if created:
        Profile.objects.create(user=instance)


post_save.connect(create_user_profile, sender=User)