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 [email protected]
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
-~----------~----~----~----~------~----~------~--~---