Skip to content

Commit bc1ee84

Browse files
committed
Fix authtoken.TokenProxy error when not installed in Django apps
1 parent 2e721cd commit bc1ee84

File tree

1 file changed

+20
-11
lines changed

1 file changed

+20
-11
lines changed

rest_framework/authtoken/models.py

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import os
33

44
from django.conf import settings
5+
from django.core.exceptions import ImproperlyConfigured
56
from django.db import models
67
from django.utils.translation import gettext_lazy as _
78

@@ -40,14 +41,22 @@ def __str__(self):
4041
return self.key
4142

4243

43-
class TokenProxy(Token):
44-
"""
45-
Proxy mapping pk to user pk for use in admin.
46-
"""
47-
@property
48-
def pk(self):
49-
return self.user.pk
50-
51-
class Meta:
52-
proxy = True
53-
verbose_name = "token"
44+
if 'rest_framework.authtoken' in settings.INSTALLED_APPS:
45+
class TokenProxy(Token):
46+
"""
47+
Proxy mapping pk to user pk for use in admin.
48+
"""
49+
@property
50+
def pk(self):
51+
return self.user.pk
52+
53+
class Meta:
54+
proxy = True
55+
verbose_name = "token"
56+
else:
57+
class TokenProxy:
58+
def __init__(self, *args, **kwargs):
59+
raise ImproperlyConfigured(
60+
'"rest_framework.authtoken" must be in your '
61+
'settings.INSTALLED_APPS to use the Token or TokenProxy '
62+
'model.')

0 commit comments

Comments
 (0)