mirror of
https://github.com/encode/django-rest-framework.git
synced 2024-11-26 03:23:59 +03:00
Moved function for getting correct user model to compat.py
This commit is contained in:
parent
cd482c0ad2
commit
8eb4bb8090
|
@ -1,29 +1,16 @@
|
|||
import uuid
|
||||
import hmac
|
||||
from hashlib import sha1
|
||||
from rest_framework.compat import User
|
||||
from django.db import models
|
||||
from django import VERSION
|
||||
|
||||
|
||||
if VERSION[:2] in ((1, 5,),):
|
||||
from django.conf import settings
|
||||
if hasattr(settings, 'AUTH_USER_MODEL'):
|
||||
user_model = settings.AUTH_USER_MODEL
|
||||
else:
|
||||
from django.contrib.auth.models import User as user_model
|
||||
else:
|
||||
try:
|
||||
from django.db.models.auth import User as user_model
|
||||
except ImportError:
|
||||
raise ImportError('User model is not to be found.')
|
||||
|
||||
|
||||
class Token(models.Model):
|
||||
"""
|
||||
The default authorization token model.
|
||||
"""
|
||||
key = models.CharField(max_length=40, primary_key=True)
|
||||
user = models.OneToOneField(user_model, related_name='auth_token')
|
||||
user = models.OneToOneField(User, related_name='auth_token')
|
||||
created = models.DateTimeField(auto_now_add=True)
|
||||
|
||||
def save(self, *args, **kwargs):
|
||||
|
|
|
@ -27,6 +27,20 @@ def get_concrete_model(model_cls):
|
|||
return model_cls
|
||||
|
||||
|
||||
# Django 1.5 add support for custom auth user model
|
||||
if django.VERSION >= (1, 5):
|
||||
from django.conf import settings
|
||||
if hasattr(settings, 'AUTH_USER_MODEL'):
|
||||
User = settings.AUTH_USER_MODEL
|
||||
else:
|
||||
from django.contrib.auth.models import User
|
||||
else:
|
||||
try:
|
||||
from django.db.models.auth import User
|
||||
except ImportError:
|
||||
raise ImportError('User model is not to be found.')
|
||||
|
||||
|
||||
# First implementation of Django class-based views did not include head method
|
||||
# in base View class - https://code.djangoproject.com/ticket/15668
|
||||
if django.VERSION >= (1, 4):
|
||||
|
|
Loading…
Reference in New Issue
Block a user