I'm trying to get django-guardian to work with my app. I followed the installation and configuration steps in the django-guardian documentation. It fails to assign permissions with the "ImproperlyConfigured: AUTH_USER_MODEL refers to model 'auth.User' that has not been installed".
I've read the related Django docs and understand that the AUTH_USER_MODEL setting uses the "app_label.UserModel" format when using a custom user model. I'm not using a custom user model but the default django one.
All issues and solutions I found in the internets were related to custom user models which I don't think applies to me.
I'm using django 1.6.1 and django-guardian 1.1.1. dj-guardaian tutorial:
http://django-guardian.readthedocs.org/en/latest/userguide/assign.html
I tried to set the settings.AUTH_USER_MODEL = 'guardian.User' to no avail.
Any help appreciated!
Cheers
These are the exact steps (after importing settings):
>>> from django.contrib.auth.models import User
>>> john = User.objects.get(id=2)
>>> john
<User: john>
>>> from mtm.models import Sharing
>>> obj = Sharing.objects.get(id=1)
>>> obj
<Sharing: Sharing object>
>>> john.has_perm('mtm.change_sharing', obj)
False
>>> from guardian.shortcuts import assign_perm
>>> assign_perm('mtm.change_sharing', john, obj)
Traceback (most recent call last):
File "<pyshell#21>", line 1, in <module>
assign_perm('mtm.change_sharing', john, obj)
File "/usr/local/lib/python2.7/dist-packages/guardian/shortcuts.py", line 71, in assign_perm
user, group = get_identity(user_or_group)
File "/usr/local/lib/python2.7/dist-packages/guardian/utils.py", line 73, in get_identity
if isinstance(identity, get_user_model()):
File "/usr/local/lib/python2.7/dist-packages/django/contrib/auth/__init__.py", line 129, 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 'auth.User' that has not been installed
settings.py
import os
import djcelery
djcelery.setup_loader()
CELERY_RESULT_BACKEND='djcelery.backends.database:DatabaseBackend'
BASE_DIR = os.path.dirname(os.path.dirname(__file__))
TEMPLATE_DIRS = [os.path.join(BASE_DIR, 'templates')]
# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/1.6/howto/deployment/checklist/
# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY =
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True
TEMPLATE_DEBUG = True
ALLOWED_HOSTS = []
# Application definition
INSTALLED_APPS = (
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'ss',
'debug_toolbar',
'djcelery',
'mtm',
'guardian',
)
MIDDLEWARE_CLASSES = (
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
)
ROOT_URLCONF = 'p4.urls'
WSGI_APPLICATION = 'p4.wsgi.application'
# Database
# https://docs.djangoproject.com/en/1.6/ref/settings/#databases
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
}
}
# Internationalization
# https://docs.djangoproject.com/en/1.6/topics/i18n/
LANGUAGE_CODE = 'en-us'
TIME_ZONE = 'UTC'
USE_I18N = True
USE_L10N = False
USE_TZ = True
#changed the default display formats
DATETIME_FORMAT = 'Y-m-d H:i:s'
DATE_FORMAT = 'Y-m-d'
TIME_FORMAT = 'H:i:s'
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/1.6/howto/static-files/
STATIC_URL = '/static/'
MEDIA_ROOT = '/home/kp/workspace/p4/'
MEDIA_URL = 'http://localhost:8000/media/'
AUTHENTICATION_BACKENDS = (
'django.contrib.auth.backends.ModelBackend',
'guardian.backends.ObjectPermissionBackend',
)
ANONYMOUS_USER_ID = -1