Am trying to get a random photo from each album from the data created by syncr. The model (abbreviated) looks like this:
class Album(models.Model):
title = models.CharField(max_length=200)
photos = models.ManyToManyField('Photo')
class Photo(models.Model):
title = models.CharField(max_length=200)
I've tried lots of different approaches with no success. Is this another easy one?
Take 2: Final code:
def galleries(request, template_name='galleries.html'):
albums = Album.objects.select_related().all()
album_list = []
for album in albums:
album_list.append({'title':album.title, 'id':album.id, 'photo':album.random_photo()})
return render_to_response(template_name, {
"album_list": album_list,
})