Hello,
I have:
class Gallery(models.Model):
...
class Image(models.Model):
gallery = models.ForeignKey(Gallery)
...
Now, on some page, I am listing all galleries and I want for every gallery
first three (or three flagged, ...) images as thumbnails. I can go through
each gallery and make another query to load these three images, but it
isn't very effective. I come from PHP, there I would do such things:
SELECT * FROM `Gallery`
Then create an instance of Gallery object, take all galleries IDs and make
second query:
SELECT * FROM `Image` WHERE `id_gallery` IN (...)
where ... are all Galleries IDs from previous query. Then create instances
of Image object and connect it with appropriate Gallery object.
1. How to do such thing in Django?
2. And second question, does Gallery knows about Image? In other words, if
I have an Gallery object (e.g. "gal"), can I access to Image through
Gallery? Something like gal.Image[0] for first image in the gallery.
Thanks,
Martin
--
You received this message because you are subscribed to the Google Groups "Django
users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at
http://groups.google.com/group/django-users?hl=en.