gpt4 book ai didi

python - NoneType 似乎被评估为 True

转载 作者:太空宇宙 更新时间:2023-11-04 04:39:18 25 4
gpt4 key购买 nike

<分区>

我有这个错误:

  File "/boo/foot/routing/models.py", line 133, in indexing
contact = self.contact.get_full_name() if self.contact else '',
AttributeError: 'NoneType' object has no attribute 'get_full_name'

我的代码是:

class Visit(models.Model):
contact = models.ForeignKey(Contact, on_delete=models.SET_NULL, null=True, blank=True )


def indexing(self):
obj = VisitIndex(
meta = { 'id' : self.id },
contact = self.contact.get_full_name() if self.contact else '',
)
print(obj)
obj.save()

索引方法附在post_save信号上:

@receiver(post_save, sender = Visit)
def index_post(sender, instance, **kwargs):
instance.indexing()

我正在测试 self.contact 是否不是假的以便获得 get_full_name()... 然而,似乎即使使用 NoneType 它也能到达那部分。问题出在哪里?

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com