我在两个不同的应用程序中有两个Django models.py
。
processor app models.py
from address.models import Address
...defining clasess
class Displayble(models.Model):
# It has no DB fields
address app models.py
from processor.models import Displayable
class Address(models.Model, Displayble):
...some fields, stored in DB
将Dispalyble
类移动到另一个文件是解决此依赖关系的唯一选择吗?
答案 0 :(得分:5)
使用django' s Address
导入apps.get_model
模型。 https://docs.djangoproject.com/en/1.11/ref/applications/#django.apps.apps.get_model
在processor app models.py
替换
from address.models import Address
...defining clasess
class Displayble(models.Model):
# It has no DB fields
使用
from django.apps import apps
Address = apps.get_model(app_label='address', model_name='Address')
....go ahead and use Address as though imported
class Displayable(models.Model):
...