class B(models.Model): whatever = models.TextField(blank=True) @staticmethod def are_we_ok(): return False class A(models.Model) text = models.TextField(blank=True) @staticmethod def is_everything_ok(): if not B.are_we_ok(): raise B.DoesNotExist A.is_everything_ok()
为什么我收到错误:
File "asdf/models.py",line x,in is_everything_ok if not B.are_we_ok(): AttributeError: 'nonetype' object has no attribute 'are_we_ok'
但是,如果我这样做:
class A(models.Model) text = models.TextField(blank=True) @staticmethod def is_everything_ok(): from asdf.models import B if not B.are_we_ok(): raise B.DoesNotExist
有用.这对我没有任何意义.这是巨大的Django应用程序的一部分.任何想法可能会导致什么样的情况? (例如,循环依赖可能吗?)
更新: