我有这些模特:
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
任何建议?
答案 0 :(得分:11)
for contact in participant.person.mailcontact_set.all():