Answer the question
In order to leave comments, you need to log in
What is the correct logic for importing modules in such a case?
There are such models:
app1/models.py:
from django.db import models
from app2.models import B
from app3.models import C
class A(models.Model):
pass
from django.db import models
from app1.models import A
class B(models.Model):
data = models.ForeignKey(A)
from django.db import models
class C(models.Model):
pass
from django.db import models
from app1.models import A
class D(models.Model):
data = models.ForeignKey(models.Model)
Answer the question
In order to leave comments, you need to log in
ran into this problem not too long ago. Now my model files look like this:
app2/models.py :
from django.db import models
class B(models.Model):
data = models.ForeignKey('app1.A')
from django.db import models
from django.apps import apps
class B(models.Model):
data = models.ForeignKey('app1.A')
def some_method(self):
a_class = apps.get_model('app1', 'A')
a_object = a_class.objects.get(id=1)
...
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question