9
相關的對象我有這些模型:循環訪問在Django
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,'[email protected]',emails,fail_silently=False)
我已經改變了這種代碼在許多方面,但我反覆出現此錯誤:
global name 'participant__person__mailContact_set' is not defined
有什麼建議嗎?
他剛剛學習,爲什麼downvote?問題很明顯,他發佈了相關的代碼。 – jpic 2012-03-02 07:48:12