Note that there are some explanatory texts on larger screens.

plurals
  1. PODjango 1.5: Accessing custom user model fields in models.py
    primarykey
    data
    text
    <p>I'm working on a Django 1.5 project and I have a custom user model (let's call it <code>CustomUser</code>). Another app (SomeApp) needs to reference this custom user model. For the purposes of ForeignKey and such, the Django documentation says to use</p> <pre><code>User = settings.AUTH_USER_MODEL </code></pre> <p>However, some functions in SomeApp.models need to access what would have formerly been known as <code>User.objects</code>. But User is now a string and not a class, so <code>User.objects</code> fails. The alternative would be</p> <pre><code>from django.contrib.auth import get_user_model User = get_user_model() </code></pre> <p>Which works in other modules, but when I use this in models.py of SomeApp, Django raises an error:</p> <blockquote> <p>ImproperlyConfigured("AUTH_USER_MODEL refers to model '%s' that has not been installed" % settings.AUTH_USER_MODEL)</p> </blockquote> <p>Any ideas?</p> <p>EDIT 1 - Traceback:</p> <pre><code>Traceback (most recent call last): File "&lt;console&gt;", line 1, in &lt;module&gt; File "...\django-badger\badger\__init__.py", line 7, in &lt;module&gt; from badger.models import Badge, Award, Progress File "...\django-badger\badger\models.py", line 26, in &lt;module&gt; User = get_user_model() File "...\lib\site-packages\django\contrib\auth\__init__.py", line 127, in get_user_model raise ImproperlyConfigured("AUTH_USER_MODEL refers to model '%s' that has not been installed" % settings.AUTH_USER_MODEL) ImproperlyConfigured: AUTH_USER_MODEL refers to model 'MyApp.AuthUser' that has not been installed </code></pre> <p>EDIT 2 - INSTALLED_APPS settings:</p> <pre><code>INSTALLED_APPS = ( 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.sites', 'django.contrib.messages', 'django.contrib.staticfiles', 'django.contrib.admin', 'django.contrib.admindocs', 'south', 'MyApp', # this is where my user model is defined 'SomeApp', # I try to use get_user_model() in this app's models.py; doesn't work. 'social_auth', ) </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload