Answer the question
In order to leave comments, you need to log in
How to solve such error in django?
What needs to be changed in the code?
from django.db.models.signals import post_save
from django.contrib.auth.models import User
from django.dispatch import receiver
from .models import Profile
@receiver(post_save, sender=User)
def create_profile(sender, instance, created, **kwargs):
if created:
Profile.objects.create(user=instance)
@receiver(post_save, sender=User)
def save_profile(sender, instance, **kwargs):
instance.profile.save()
Answer the question
In order to leave comments, you need to log in
You lose the save method arguments. Fix like this:
class Profile(models.Model):
...
def save(self, *args, **kwargs):
super().save(*args, **kwargs)
...
save_profile
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question