from itertools import chainfrom action.models import Actionfrom adventure.models import Adventure
def windows_games(request): win_action = Action.objects.filter(os='windows') win_adventure = Adventure.objects.filter(os='windows')
combined_list = list(chain(win_action,win_adventure)) context = ['combined_list':combined_list,] In the windows_games view in others/views.py, you are using the filter() method on the Action and Adventure models to get the action and adventure games that have the 'os' field set to 'windows'. Then you are using the itertools.chain() function to combine the two querysets into a single list, and storing that list in the variable combined_list. The context variable is not created correctly, it should be context = {'combined_list': combined_list}
In the template others/os/windows_game.html, to output the results of the combined_list you should use a for loop to iterate over the list and display each item. Also, it seems that you are trying to access the game_pic attribute of the objects in the combined_list, but the models you have defined (Action and Adventure) do not have a field called game_pic
{% for game in combined_list %} <img src="{{ game.game_pic }}"> <p>{{ game.name }}</p> {% endfor %}
It would be a good idea to add a __str__ method to the models in order to return the name of the game, and also to add a field game_pic if you want to display the image of the game.
--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/0b3af5d4-bb40-430c-9016-c2c7fa6108fan%40googlegroups.com.