Django 和相互交互的应用程序很容易遇到导入问题。我的问题很简单:
最小化循环进口的公认流程是什么,或者有没有人提出一个公认的编码标准来减少他们愿意分享的这些。
我正在寻找可以标准化的良好原则。
楷模
class Program(models.Model):
group = models.ForeignKey(Group, related_name="%(app_label)s_%(class)s_related")
对比
class Program(models.Model):
group = models.ForeignKey('auth.Group', related_name="%(app_label)s_%(class)s_related")
意见:
class ProgramDetailView(DetailView):
"""Detail view of the EEP Program"""
def get_queryset(self):
"""Narrow this based on your company"""
from apps.company.models import Company
company = Company.objects.get(name="foo")
return Program.objects.filter(company = company)
vs(这往往会导致问题..
from apps.company.models import Company
class ProgramDetailView(DetailView):
"""Detail view of the EEP Program"""
def get_queryset(self):
"""Narrow this based on your company"""
company = Company.objects.get(name="foo")
return Program.objects.filter(company = company)
这样做的问题是您倾向于在整个地方进行大量导入..