My mistake, colon needed after "join" {{game.platforms.all|join:", "}}
On 9 янв, 00:49, Darthmahon <[EMAIL PROTECTED]> wrote: > Hi Alex, > > I want to do what you've shown me; print a list of games with the name > of the platform(s). I've been trying to find an answer to this in all > of the docs but the examples given never use real-world examples and > everything seems to be done on the Python shell, which is now how I am > using it. The views code is from examples I have found - I agree it is > strange and yours is much cleaner! > > Thanks for your reply, I've got this semi-working now, only problem is > it has an error. With DEBUG=True on it gives this: > > join requires 1 arguments, 0 provided > > Does this mean no results (platforms) are being passed through? > > On Jan 8, 9:35 pm, Alex Koshelev <[EMAIL PROTECTED]> wrote: > > > What are you want to do? Do you read docs? > > The view's code is very strange. So many times appears word "list". > > > May be you what get all games with platforms, so > > > def games(request): > > games = Game.objects.all() > > return render_to_response('games/games.html', > > { 'games':games }, context_instance=RequestContext(request)) > > > {% for game in games %} > > Title: {{ game.title }} </br> > > Platform: {{game.platforms.all|join", "}}</br> > > {% endfor %} > > > On 9 янв, 00:14, Darthmahon <[EMAIL PROTECTED]> wrote: > > > > Hey, > > > > Can't get my head around this. Basically I have a model that includes > > > a manytomany field like this: > > > > ########################## > > > File: /games/models.py > > > ########################## > > > class Platform(models.Model): > > > title = models.CharField(maxlength=30) > > > > def __unicode__(self): > > > return self.title > > > > class Game(models.Model): > > > title = models.CharField(maxlength=30) > > > platforms = models.ManyToManyField(Platform) > > > > def __unicode__(self): > > > return self.title > > > ########################## > > > > I then request all of the games using this function: > > > > ########################## > > > File: /games/views.py > > > ########################## > > > def games(request): > > > > games_listing = [] > > > games = Game.objects.all() > > > count = games.count() > > > for games_list in games: > > > games_dict = {} > > > games_dict['list_object'] = games_list > > > games_listing.append(games_dict) > > > return render_to_response('games/games.html', { 'games_listing': > > > games_listing, 'count': count }, > > > context_instance=RequestContext(request)) > > > ########################## > > > > As you can see, it calls the template games/games.html which looks > > > like this: > > > > ########################## > > > File: /games/views.py > > > ########################## > > > {% for list_dict in games_listing %} > > > Title: {{ list_dict.list_object.title }} </br> > > > Platform:{{ list_dict.list_object.platform.title }} </br> > > > {% endfor %} > > > ########################## > > > > This is where I'm stuck. It prints out the name of the game, but > > > doesn't print out the name of the platform. I was assuming Django > > > would make it easy to print out the title of the Platform linked via > > > the ManyToMany field? > > > > Any ideas? --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---