A
A
Arseny Sokolov2019-01-18 16:19:18
Django
Arseny Sokolov, 2019-01-18 16:19:18

How to cross-link models of different Django applications?

The situation is this:

  • There are 2 applications that are loaded in turn in settings.py, first web, then catalog
  • The Web application imports models from the Catalog application
  • And in the Catalog application, it is not possible to import models from the Web application due to the order in which applications are loaded

How to cross-link models of different Django applications?
If you change the order of loading applications, then the situation changes completely opposite.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey Gornostaev, 2019-01-18
@ArsenBespalov

Do not import model classes, but pass in ForeignKeyor ManyToManyFieldpass a string with the class name, instead of the class itself:

class A(models.Model):
    b = models.ForeignKey('B')

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question