Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

241
Views
Importing from views to models in Django

I have something like this in one of my apps's models.py :

class Account(AbstractBaseUser):
    email = models.EmailField(unique=True)

I want to import a class from another app's views.py as below:

from anotherapp.views import MyClass

The problem is in the first lines of anotherapp.views file, I imported the Account class. So when I want to import MyClass into my models.py file, this error raises :

ImportError: cannot import name Account
about 4 years ago · Santiago Trujillo
1 answers
Answer question

0

That is circular import error you are encountering. While it is bad practice to import from views to models in Django, if you still want to, you can follow methods in this question to resolve it.

Here are few alternative ways that can be considered as good practice:

  • You can consider importing other low-level modules exist within anotherapp instead of MyClass (not depending on views.py)
  • You can use Django's signals to catch anotherapp's events project wide and act according to.
  • You can create a third file, say utils.py in anotherapp, move MyClass there and let anotherapp/views.py and your app's models.py import from anotherapp.utils
about 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!