To only get one image, you use a limit. like movie.images_set.all()[:1]
On Sep 22, 2:37 pm, Joshua Russo <josh.r.ru...@gmail.com> wrote: > On Tue, Sep 22, 2009 at 7:23 PM, MV <li...@negativehalf.com> wrote: > > > I have a Movie model > > and I have a Image model > > the Image model has a ForeignKey(Movie) > > > Each Movie has an arbitrary amount of Images. > > > I have a view where I list all the Movies. > > For each Movie entry, I want one Image. > > > How do I do that? > > > I can do a "movies = Movies.objects.all()" and pass "movies" to the > > template, but I don't know how to attach an image > > How do I get one, and only one, Image for each Movie? > > > The only thing I can think about is using a for-loop on the returned > > list of movies, but that will hit the database an awfully lot. > > You can access the images via moves.images_set.filter()... --~--~---------~--~----~------------~-------~--~----~ 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 django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~----------~----~----~----~------~----~------~--~---