I am a newbie of django. I want to make a ForeignKey to the auth_user
table.
I try to do that:
user = models.ForeignKey(auth_user)
It cause the error:
NameError: name 'auth_user' is not defined
So, can somebody tell me how to import auth_user
.
Since foreign keys accept strings, you can use the AUTH_USER_MODEL
setting in your foreign key.
from django.conf import settings
class MyModel(models.Model):
user = models.ForeignKey(settings.AUTH_USER_MODEL)
This works whether you are using the built in User
model, or a custom model.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With