Hay I have a model like this
def Photo(models.Model):
# Photo object fields...
def PhotoThread(models.Model):
photo = models.ForeignKey(Photo)
message = models.TextField(blank=True)
reply_to = models.ForeignKey('self', related_name='replies', null=True, blank=True)
votes = models.IntegerField()
As you can see a Thread object has a reply_to field, so that Threads can become children of other Threads.
I can do stuff like –
photo = Photo.objects.get(pk=1)
threads = photo.photothread_set.all()
This will get the threads to a Photo, however, this system allows replies to also have replies.
How would i go about looping through all replies and getting replies for those (all the way down to the maxiumum number of replies we have).
I want to display this as a nested HTML list. Also i want to be able to order all Threads and replies by the ‘votes’ field.
Thanks
Write an inclusion template tag that uses itself in its template.