Cross import into django

For example, I have 2 applications: alpha and beta in alpha / models.py importing a model from beta.models and in beta /models.py importing a model from alpha.models

manage.py validate says ImportError: cannot import ModelName name

How to solve this problem?

+3
source share
1 answer

I had this problem in the past, there are two models that refer to each other, that is, to use the field ForeignKey. There is an easy way to handle this: Django documentation :

, , , :

, beta/models.py :

class BetaModel(models.Model):
    alpha = models.ForeignKey('alpha.AlphaModel')
    ...

alpha.models .

+7

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


All Articles