I am sorry if this is a duplicate. I did post the same on Django REST Framework. I was not sure where I should post this.
-- I am trying to add some custom fields to oauth2. I am using python 3.4 and django 1.8.
I am having varying errors. But with the combination I got below, the error I get is
ERRORS:
logistics.CustomUser.user: (fields.E301) Field defines a relation with the model 'auth.User', which has been swapped out.
HINT: Update the relation to point at 'settings.AUTH_USER_MODEL'.
oauth2_provider.AccessToken.application: (fields.E304) Reverse accessor for 'AccessToken.application' clashes with reverse accessor for 'AccessToken.user'.
HINT: Add or change a related_name argument to the definition for 'AccessToken.application' or 'AccessToken.user'.
oauth2_provider.AccessToken.user: (fields.E304) Reverse accessor for 'AccessToken.user' clashes with reverse accessor for 'AccessToken.application'.
HINT: Add or change a related_name argument to the definition for 'AccessToken.user' or 'AccessToken.application'.
oauth2_provider.Grant.application: (fields.E304) Reverse accessor for 'Grant.application' clashes with reverse accessor for 'Grant.user'.
HINT: Add or change a related_name argument to the definition for 'Grant.application' or 'Grant.user'.
oauth2_provider.Grant.user: (fields.E304) Reverse accessor for 'Grant.user' clashes with reverse accessor for 'Grant.application'.
HINT: Add or change a related_name argument to the definition for 'Grant.user' or 'Grant.application'.
oauth2_provider.RefreshToken.application: (fields.E304) Reverse accessor for 'RefreshToken.application' clashes with reverse accessor for 'RefreshToken.user'.
HINT: Add or change a related_name argument to the definition for 'RefreshToken.application' or 'RefreshToken.user'.
oauth2_provider.RefreshToken.user: (fields.E304) Reverse accessor for 'RefreshToken.user' clashes with reverse accessor for 'RefreshToken.application'.
HINT: Add or change a related_name argument to the definition for 'RefreshToken.user' or 'RefreshToken.application'.
Here is my model:
from django.db import models
from django.contrib.auth.models import User
from oauth2_provider.models import AbstractApplication
from django.contrib.auth.models import AbstractUser,BaseUserManager, AbstractBaseUser,PermissionsMixin
from django.conf import settings
from django.contrib.auth import get_user_model
class CustomUser(AbstractUser):
some_additional_field = models.BooleanField(default=False )
user = models.OneToOneField(User, on_delete=models.CASCADE)
Here is my settings.py
import os
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__ file__)))
# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/1.8/howto/deployment/ checklist/
# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = 'y_g)p7ut03#i&2zj5*$q06^f9yz%&#$wu78qn05(a88iuaa%gq' # SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True
ALLOWED_HOSTS = []
#print (os.path.join(os.path.dirname(__file__), 'template').replace('\\','/'))
# Application definition
INSTALLED_APPS = (
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'oauth2_provider',
'corsheaders',
'custom_user',
'rest_framework',
'logistics',
'rest_framework_swagger',
'debug_toolbar',
)
MIDDLEWARE_CLASSES = (
'django.contrib.sessions.middleware.SessionMiddleware' ,
'django.middleware.common.CommonMiddleware' ,
'django.middleware.csrf.CsrfViewMiddleware' ,
'django.contrib.auth.middleware. ,SessionAuthenticationMiddlewar e'
'oauth2_provider.middleware.OAuth2TokenMiddleware' ,
'django.contrib.auth.middleware. ,SessionAuthenticationMiddlewar e'
'oauth2_provider.middleware.OAuth2TokenMiddleware' ,
'django.contrib.auth.middleware. ,AuthenticationMiddleware'
'django.contrib.auth.middleware. ,SessionAuthenticationMiddlewar e'
'django.contrib.messages.middleware.MessageMiddleware' ,
'django.middleware.clickjacking. ,XFrameOptionsMiddleware'
'django.middleware.security.SecurityMiddleware' ,
'corsheaders.middleware.CorsMiddleware' )
ROOT_URLCONF = 'logistics.urls'
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates' ,
'DIRS': [],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug' ,
'django.template.context_processors.request' ,
'django.contrib.auth.context_processors.auth' ,
'django.contrib.messages.context_processors.messages' ,
],
},
},
]
OAUTH2_PROVIDER = {
'AUTHORIZATION_CODE_EXPIRE_SECONDS' : 60 * 60,
'ACCESS_TOKEN_EXPIRE_SECONDS': 60 * 60 * 24 * 7,
# this is the list of available scopes
'SCOPES': {'read': 'Read scope', 'write': 'Write scope', 'groups': 'Access to your groups'}
}
OAUTH2_PROVIDER_APPLICATION_MODEL='logistics.CustomUser'
REST_FRAMEWORK = {
'DEFAULT_AUTHENTICATION_CLASSES' : (
'oauth2_provider.ext.rest_framework. ,OAuth2Authentication'
),
'DEFAULT_PERMISSION_CLASSES': (
'rest_framework.permissions.IsAuthenticated' ,
),
}
WSGI_APPLICATION = 'logistics.wsgi.application'
CORS_ORIGIN_ALLOW_ALL = True
AUTH_USER_MODEL='logistics.CustomUser'
TEMPLATE_DIRS = (
os.path.join(os.path.dirname(__file__), 'template').replace('\\','/'),
)
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates' ,
'DIRS': [os.path.join(BASE_DIR, 'logistics/')],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug' ,
'django.template.context_processors.request' ,
'django.contrib.auth.context_processors.auth' ,
'django.contrib.messages.context_processors.messages' ,
],
},
},
]
AUTHENTICATION_BACKENDS = (
'oauth2_provider.backends.OAuth2Backend' ,
# Uncomment following if you want to access the admin
'django.contrib.auth.backends.ModelBackend' #'...',
)
# Database
# https://docs.djangoproject.com/en/1.8/ref/settings/# databases
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
}
}
OAUTH_ENABLE_APPROVAL_PROMPT_BYPASS = False
#AUTH_USER_MODEL = 'logistics.MyLogistics'
# Internationalization
# https://docs.djangoproject.com/en/1.8/topics/i18n/
LANGUAGE_CODE = 'en-us'
TIME_ZONE = 'UTC'
USE_I18N = True
USE_L10N = True
USE_TZ = True
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/1.8/howto/static-files/
STATIC_URL = '/static/'
TEMPLATE_DIRS = (
os.path.join(BASE_DIR, 'templates'),
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/25ed6762-860f-4c82-b3a4-39664cf78827%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
No comments:
Post a Comment