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应用程序的一部分.任何想法可能会导致什么样的情况? (例如,循环依赖可能吗?)
更新:
解决方法
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。