2👍
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 ofMyClass
(not depending onviews.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
inanotherapp
, moveMyClass
there and letanotherapp/views.py
and your app’smodels.py
import fromanotherapp.utils
Source:stackexchange.com