我使用django-registrations,而我在admin.py中添加了这段代码
from django.contrib import admin
from customer.models import Customer
from .models import UserProfile
from django.contrib.auth.admin import UserAdmin
from django.contrib.auth import get_user_model
class UserProfileInline(admin.StackedInline):
model = UserProfile
can_delete = False
class UserProfileAdmin(UserAdmin):
inlines=(UserProfileInline, )
admin.site.unregister(get_user_model())
admin.site.register(get_user_model(), UserProfileAdmin)
admin.site.register(Customer)
我收到错误:
" cannot import name get_user_model "
in admin.py
我做错了什么?
答案 0 :(得分:4)
get_user_model
中有{p> version >= 1.5
,您可能正在运行Django version < 1.5
。升级Django,问题就会消失。
或者使用它代替Django版本&lt; 1.5:
from django.contrib.auth.models import User