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)
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)
- Using nested Django transaction.atomic() to handle exceptions?
- How to use MultipleChoiceField in django-widget-tweaks?
- How to get the instance of the model in clean()
- Need Assistane in converting django model admin save method to Django Rest Framework
Source:stackexchange.com