Search code examples
djangoauthenticationdjango-modelsmodel

Django auth and import auth.User


Hi i follow djangogirls tutorial for learning django

in the tutorial they use

author = models.ForeignKey('auth.User', on_delete=models.CASCADE)

But they import nothing for auth.User Why? i see in many tutorials this code:

from django.contrib.auth.models import User

whats diffrent beetween calling without import and calling with import

Thanks.


Solution

  • Its used to avoid running into a circular import situation,

    But even better is using get_user_model() see here in the docs