On Wed, Aug 20, 2008 at 11:17 PM, Benjamin Buch <[EMAIL PROTECTED]> wrote:
> > > Hi Garret, > > > How about sending the template something like: > > > > songs = Recording.objects.filter(represents_song=True) > > > > A custom manager seems like overkill for this situation (If I'm > > understanding you right). > > > > - Garrett > > this is indeed a plausible sollution. > I then had to access the songs' data via the recording in the template > like > > {% for recording in songs %} > {{ recording.song.title }} > {{ recording.song.description }} > {{ recording.mp3 }} > {% endfor %} > > For my special case I think this should work, because every song has > exact one recording that represents it. > And you are right, a custom manager seems like overkill in this case. > But out of interest, it turned out to be a more general question for me: > > How to limit the query set of a related object? > > I think this can only be done via a custom manager... > > Thanks! > > -benjamin > Benjamin, I'm not sure i understand you question. You can filter via the attributes of a related object like this: Recording.objects.filter(song__artist="Ben Folds") For more on the filter tag, go here: http://www.djangoproject.com/documentation/db-api/#filter-kwargs As I understand it, a custom manager is just a convenience to abstract out commonly used filter patterns. This means that there is nothing that "can only be done via a custom manager" that can't also be done directly to a queryset. (Please someone correct me if I'm wrong.) For more on custom managers, read this: http://www.djangoproject.com/documentation/models/custom_managers/ - Garrett > > > > --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---