I get a TypeError when I use the following code in my Django Template:
{% for signature in petition.get_signatures %}
{% include 'petition/signature.html' with petition=petition %}
{% endfor %}
Here are my models and classes:
class Petition(models.Model):
title = models.CharField(max_length= 90, default="Enter petition title here")
created_on = models.DateTimeField(auto_now_add=True)
image = models.ImageField(null=False, upload_to='static/petition-photos/%Y/%m/%d')
video = models.CharField(max_length=600, default="Enter an external video link")
petition = models.TextField(null=False, default="Type your petition here")
created_by = models.ForeignKey(User)
def total_likes(self):
return self.like_set.count()
def __str__(self):
return self.title[:50]
def get_signatures(self):
return self.signature_set.all
class Signature(models.Model):
petition= models.ForeignKey(Petition)
user = models.ForeignKey(User)
description = models.TextField(null=False, blank=False)
anonymous = models.BooleanField()
created_at = models.DateTimeField(auto_now_add=True)
def __str__(self):
return self.petition
I get the following error message when I load my template view page with the 'for' condition. The error message I get is 'method' object is not iterable. What might I be doing wrong? Any solutions? I'm kind of a noob so if you could explain the solution too, that would be great.