cannot import name get_user_model

2024/9/23 3:18:05

I use django-registrations and while I add this code in my admin.py

   from django.contrib import adminfrom customer.models import Customerfrom .models import UserProfilefrom django.contrib.auth.admin import UserAdminfrom django.contrib.auth import get_user_modelclass UserProfileInline(admin.StackedInline):model = UserProfilecan_delete = Falseclass UserProfileAdmin(UserAdmin):inlines=(UserProfileInline, )admin.site.unregister(get_user_model())admin.site.register(get_user_model(), UserProfileAdmin)admin.site.register(Customer)

I receive an error:

" cannot import name get_user_model "
in admin.py

what am I doing wrong?

Answer

get_user_model is available in Django version >= 1.5 you are probably running Django version < 1.5. Upgrade the Django and the problem will be gone.

Or use this instead for Django version < 1.5:

from django.contrib.auth.models import User
https://en.xdnf.cn/q/71869.html

Related Q&A

pytest: Best Way To Add Long Test Description in the Report

By default pytest use test function names or test files names in pytest reportsis there any Best way to add test description (Long test name) in the report with out renaming the files or functions usin…

Adding a calculated column to pandas dataframe

I am completely new to Python, pandas and programming in general, and I cannot figure out the following:I have accessed a database with the help of pandas and I have put the data from the query into a …

Scipy: Centroid of convex hull

how can I calculate the centroid of a convex hull using python and scipy? All I found are methods for computing Area and Volume.regards,frank.

Creating a montage of pictures in python

I have no experience with python, but the owner of this script is not responding.When I drag my photos over this script, to create a montage, it ends up cutting off half of the last photo on the right …

stop python program when ssh pipe is broken

Im writing a python script with an infinite while loop that I am running over ssh. I would like the script to terminate when someone kills ssh. For example:The script (script.py):while True:# do someth…

How do I export a TensorFlow model as a .tflite file?

Background information:I have written a TensorFlow model very similar to the premade iris classification model provided by TensorFlow. The differences are relatively minor: I am classifying football ex…

Using plotly in Jupyter to create animated chart in off-line mode

Ive been trying to get the "Filled-Area Animation in Python" example to work using plotly in offline mode in a Jupyter notebook. The example can be found here: https://plot.ly/python/filled-a…

Django: How to unit test Update Views/Forms

Im trying to unit test my update forms and views. Im using Django Crispy Forms for both my Create and Update Forms. UpdateForm inherits CreateForm and makes a small change to the submit button text. Th…

Why is Python faster than C++ in this case?

A program in both Python and C++ is given below, which performs the following task: read white-space delimited words from stdin, print the unique words sorted by string length along with a count of eac…

Python - write headers to csv

Currently i am writing query in python which export data from oracle dbo to .csv file. I am not sure how to write headers within file. try:connection = cx_Oracle.connect(user,pass,tns_name)cursor = con…