我有两个模块,如下所示:
--models.py
from myapp.filters import EntityFilter
class Entity(models.Model):
//model definition
def someMethod(self):
entities = EntityFilter(...)
--filters.py
from myapp.models import Entity
class EntityFilter(django_filters.FilterSet):
class Meta:
model = Entity
// ...
显然我得到了错误ImportError: cannot import name Entity
我应该如何重新组织我的代码?
您如何看待这个解决方案?可以吗?
class Entity(models.Model):
//model definition
def someMethod(self):
from myapp.filters import EntityFilter
entities = EntityFilter(...)
它工作正常...