私は 2 つのアプリを持っていcommonapp
ますapp1
。
ここにありcommonapp/models.py
ます:
from django.db import models
#from app1.models import SpecificFields
# Create your models here.
class CommonFields(models.Model):
a = models.IntegerField(default = 0)
class Meta:
abstract = True
class SomeFields(models.Model):
# a = models.ForeignKey(SpecificFields)
a = models.ForeignKey('app1.models.SpecificFields')
そしてここにありますapp1/models.py
:
from django.db import models
from commonapp.models import CommonFields
# Create your models here.
class SpecificFields(CommonFields):
a2 = models.IntegerField(default=0)
app1
またはから SQL を実行しようとするとcommonapp
、次のエラーが発生します。
$ python manage.py sql commonapp
CommandError: One or more models did not validate:
commonapp.somefields: 'a' has a relation with model app1.models.SpecificFields,
which has either not been installed or is abstract.
これは循環依存の問題であることを認識しています。実際のクラスではなく文字列としてクラスへのパスを指定することを提案する人もいますが、それは機能しません。また、派生クラスの基本クラス名として文字列を指定することもできません。
モデルをリファクタリングしなくても、このような循環依存は可能ですか?