Cannot import name get_user_model

I use django registrations and add this code to my 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)

I get an error message:

" cannot import name get_user_model "
in admin.py

what am I doing wrong?

+4
source share
1 answer

get_user_modelavailable in Django version >= 1.5, maybe you are using Django version < 1.5. Update Django and the problem goes away.

Or use this instead for Django version <1.5:

from django.contrib.auth.models import User
+4
source

Source: https://habr.com/ru/post/1524829/


All Articles