Something like this should return an iterable list of UserSong records for user U
>>> list = UserSong.objects.filter( user=U ) Then you can iterate over it or pass that list to a template that iterates over it >>> for song in list: >>> doSomething Look here for more http://www.djangoproject.com/documentation/db-api/ On Jan 7, 3:01 pm, Darthmahon <[EMAIL PROTECTED]> wrote: > Hey, > > My ongoing quest to get a basic app working will hopefully be answered > by this question :) > > I have the following model.py file: > > File: model.py > ================================== > > from django.db import models > from django.contrib.auth.models import User > > class Song(models.Model): > title = models.CharField(maxlength=500) > > # return title of game > def __str__(self): > return self.title > > class User Song(models.Model): > # Link to user and song > user = models.ForeignKey(User) > song = models.ForeignKey(Song) > > ================================== > > In my views.py file I have a function that displays all songs: > > File: views.py > ================================== > > ...import calls... > > def song(request): > > song_listing = [] > for song_list in Song.objects.all(): > song_dict = {} > song_dict['list_object'] = song_list > song_listing.append(song_dict) > return render_to_response('song/song.html', { song_listing': > song_listing }, context_instance=RequestContext(request)) > > ================================== > > That prints out all of the songs in the database using the song/ > song.html template which works perfectly. > > Now I want to be able to print ONLY the songs a user has added to > their profile. This is done using a separate function, but the models > have been setup (I believe) correctly to link the two (Song and User). > > This is where I am struggling - how do I perform a function in my > views.py file that only gets the names of the songs a user has added? > I've been looking for some real examples of Django doing this and I > can't find anything, anyone got any advice? > > Cheers, > Chris --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---