gpt4 book ai didi

python - 迭代 Django 中的相关对象

转载 作者:太空狗 更新时间:2023-10-29 20:19:09 25 4
gpt4 key购买 nike

我有这些模型:

class Person(models.Model):
name=models.CharField(max_length=100)
family=models.CharField(max_length=100)

class MailContact(models.Model):
person=models.ForeignKey(Person)
email=models.CharField(max_length=100)
#some fields

class Participant(models.Model):
person=models.ForeignKey(Person)
#some fields

views.py 中:

   emails = []
for participant in participants:
for contact in participant__person__mailContact_set:
emails.append(contact.email)
send_mail(email_subject,email_body,'receiver_email_address@gmail.com',emails,fail_silently=False)

我以多种方式更改了此代码,但我反复收到此错误:

global name 'participant__person__mailContact_set' is not defined

有什么建议吗?

最佳答案

for contact in participant.person.mailcontact_set.all():

关于python - 迭代 Django 中的相关对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9529606/

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