【发布时间】:2014-08-05 17:01:40
【问题描述】:
我正在尝试向我的 Django 用户模型添加一些自定义逻辑,并尝试使用代理用户模型来实现。
我有一个类似这样的模型:
from django.contrib.auth.models import User
class CustomUser(User):
def custom_method(self):
return 'Something'
class Meta:
proxy = True
如果我省略 AUTH_USER_MODEL 设置,那么我可以运行 Django shell 并非常愉快地使用 CustomUser,但是,我认为我可以在我的设置中设置 AUTH_USER_MODEL,所以这是我的默认用户应用程序(例如当您使用完全自定义的用户模型时),但情况并非如此,当我尝试使用 AUTH_USER_MODEL 设置运行时,我得到:
TypeError: CustomUser cannot proxy the swapped model 'myapp.CustomUser'
这可能吗?谢谢!
【问题讨论】: