views.py で以下のエラーが発生していますが、その理由を理解できません。助けてください。
Request Method: GET
Request URL: http://localhost:8000/tribalrights/
Django Version: 1.3.1
Exception Type: AttributeError
Exception Value: 'NoneType' object has no attribute 'all'
Exception Location: /home/gunjan/tribalrights/tr/views.py in home, line 70
Python Executable: /usr/bin/python
Python Version: 2.7.3
以下は、 views.py で呼び出されている関数です。70 行目は for 宣言の次の行から始まります。
def home(request):
atrocities = Atrocity.objects.all()
cities = City.objects.all()
for atrocity in atrocities:
#this is line 69.below is line 70.
cities = atrocity.location.all()
return render_to_response('tr/home.html', {
'cities' : cities,
})
以下は、models.py の City 属性と Atrocity 属性の定義です。
class Atrocity(models.Model):
name = models.CharField(max_length=255)
dateTimeOccurred = models.DateTimeField ( null=True, blank=True )
persons = models.ManyToManyField ( Person, null=True, blank=True )
atrocityType = models.ForeignKey(AtrocityType)
description = models.CharField(max_length=255)
location = models.ForeignKey(City, null=True, blank=True)
def __unicode__(self):
return self.name
class City(models.Model):
name = models.CharField(max_length=255)
district = models.ForeignKey(District)
latitude = models.DecimalField(max_digits=13, decimal_places=10, null=True, blank=True)
longitude = models.DecimalField(max_digits=13, decimal_places=10, null=True, blank=True)
def __unicode__(self):
return self.name