*disclosure* I am SQL novice, okay */disclosure*

I have what I think is a very simple problem, but can't seem to find a
solution without writing raw SQL.

I have 2 (simplified here) models:

class Entry(models.Model):
        title = models.CharField(max_length=80)

class Image(models.Model):
        image = models.ImageField(upload_to="img/")
        entry = models.ForeignKey(Entry)

Each entry can have many images.

I would like to build a query that returns all the available Entries
and Images related to each Entry.

My view looks like this...

from xxx.xxx.models import Entry
from xxx.xxx.models import Image

def index(request):
        entry_list = Entry.objects.all()
        image_list = Image.objects.select_related('entry')

Currently, I am getting the entire list of images with each Entry,
rather than only the specific images related to an Entry (if you know
what I mean).

To illustrate, my results resemble this:

Entry 1 + Image 1, Image 2, Image 3
Entry 2 + Image 1, Image 2, Image 3
Entry 3 + Image 1, Image 2, Image 3

whereas I would like to see

Entry 1 + Image 1
Entry 2 + Image 2
Entry 3 + Image 3

I hope this make sense. If anyone would care to show me how to build
the right query, I'd be very grateful.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to