0

I am trying to run the django shell to understand what is happening to the photos when I upload them.

However when I try to filter for particular users

python manage.py shell
from django.contrib.auth.models import User
user = User.objects.filter(username='name').first()

I get the following error message:

AttributeError: Manager isn't available; 'auth.User' has been swapped for 'classroom.User'

I am guessing this has something to do with this in settings.py

AUTH_USER_MODEL = 'classroom.User'

What should I be typing to get to look at the profile model

dirkgroten
  • 20,112
  • 2
  • 29
  • 42
Emm
  • 2,367
  • 3
  • 24
  • 50

1 Answers1

2

You're correct, it does have something to do with:

AUTH_USER_MODEL = 'classroom.User'

Since you specified what I would assume is a Custom User Model. In which case you woud have to use the method get_user_model() as specified in Django's docs to reference your new User model.

from django.contrib.auth import get_user_model
User = get_user_model()
dirkgroten
  • 20,112
  • 2
  • 29
  • 42
Paolo
  • 823
  • 6
  • 18
  • Thanks, getting the error message: from django.contrib.auth import get_user_model() ^ SyntaxError: invalid syntax – Emm Jan 10 '20 at 15:34
  • 1
    @Emm take off the () in your import. – dfundako Jan 10 '20 at 15:36
  • thanks, getting this error now: ImportError: cannot import name 'get_user_model' from 'django.contrib.auth.models' (C:\Users\User\Anaconda3\lib\site-packages\dj ango\contrib\auth\models.py) – Emm Jan 10 '20 at 15:38
  • 3
    As you can see above you should import from django.contrib.auth – dirkgroten Jan 10 '20 at 15:54