Importerror: Cannot Import Name 'user'
I created custom save method for my class User. Because I have to create DriverRegistration object when I create User object. When I added only method save i received an error the
Solution 1:
Just as a matter of implementation - I think you would be better using Django signals compared to overriding the save
method.
Here's an example:
@receiver(post_save, sender=User)defsave_driver_registration(sender, instance, created, **kwargs):
if created:
DriverRegistration.objects.create(user=instance.pk)
This will create a new DriverRegistration object when a new User
entry has been created. This is arguably a better approach than overriding .save()
because with your implementation, every time you .save()
a user (for example - updating a user's name/password) - you will create a new DriverRegistration
object.
Read more here: https://docs.djangoproject.com/en/3.1/topics/signals/
Post a Comment for "Importerror: Cannot Import Name 'user'"