From 5e8cca163374a5006ca650ec9ceb17aab6c1f5d6 Mon Sep 17 00:00:00 2001 From: Serhiy Romanov Date: Wed, 15 Apr 2020 16:26:54 +0300 Subject: [PATCH] Use import_string for getting TokenModel instead of passing class --- dj_rest_auth/models.py | 6 ++---- docs/configuration.rst | 4 ++-- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/dj_rest_auth/models.py b/dj_rest_auth/models.py index 654c0ae..8410821 100644 --- a/dj_rest_auth/models.py +++ b/dj_rest_auth/models.py @@ -1,6 +1,4 @@ from django.conf import settings -from rest_framework.authtoken.models import Token as DefaultTokenModel +from django.utils.module_loading import import_string -# Register your models here. - -TokenModel = getattr(settings, 'REST_AUTH_TOKEN_MODEL', DefaultTokenModel) +TokenModel = import_string(getattr(settings, 'REST_AUTH_TOKEN_MODEL', 'rest_framework.authtoken.models.Token')) diff --git a/docs/configuration.rst b/docs/configuration.rst index c841e60..aac74c2 100644 --- a/docs/configuration.rst +++ b/docs/configuration.rst @@ -40,9 +40,9 @@ Configuration .. note:: The custom REGISTER_SERIALIZER must define a ``def save(self, request)`` method that returns a user model instance -- **REST_AUTH_TOKEN_MODEL** - model class for tokens, default value ``rest_framework.authtoken.models`` +- **REST_AUTH_TOKEN_MODEL** - path to model class for tokens, default value ``'rest_framework.authtoken.models.Token'`` -- **REST_AUTH_TOKEN_CREATOR** - callable to create tokens, default value ``dj_rest_auth.utils.default_create_token``. +- **REST_AUTH_TOKEN_CREATOR** - path to callable or callable for creating tokens, default value ``dj_rest_auth.utils.default_create_token``. - **REST_SESSION_LOGIN** - Enable session login in Login API view (default: True)