Thanks it worked but I would like to ask you, why did you use " game" in
{%for game in combined_list %} ? En what is the role of 'game'
On Sat, Jan 14, 2023, 8:35 PM Hector Mwaky <[email protected]> wrote:
>
> 1.
>
> 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}
> 2.
>
> 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
> 3.
>
> {% for game in combined_list %} <img src="{{ game.game_pic }}"> <p>{{
> game.name }}</p> {% endfor %}
> 4.
>
> 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.
> class Action(models.Model): name=models.Charfield() os=
> models.Charfield(choices=OS) game_pic = models.ImageField(upload_to=
> 'action_game_pic/') def __str__(self): return
>
>
> On Thursday, 12 January 2023 at 18:27:03 UTC+3 [email protected] wrote:
>
>> Hey! Am having a problem. And l request for your Help.
>>
>> Am having 3 apps in Django project
>> - action
>> - adventure
>> - others
>>
>>
>> #action/ models.py
>>
>> ....
>> class Action(models.Model):
>> name=models.Charfield()
>> os= models.Charfield( choices=OS)....
>>
>>
>>
>> #adventure/models.py
>>
>>
>> ....
>> class Adventure(models.Model):
>> name=models.Charfield()
>> os= models.Charfield( choices=OS)....
>>
>>
>>
>> #Others/views.py
>>
>>
>> from itertools import chain
>>
>> from action.models import Action
>>
>> from 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,]
>>
>> return render(request, 'others/os/windows_game.html' , context)
>>
>>
>>
>> #others/os/windows_game.html
>>
>> .....
>> <div class="container">
>> <img src="{{combined_list.game_pic}}">
>> <p>{{combined_list.name}}</p>
>> .....
>>
>>
>>
>>
>>
>>
>>
>>
>> 1). I need to correct me in #others/ views.py if there is any mistake
>> done.
>>
>> 2). I would like to know how to know how to write the tag that outputs
>> the results in #others/os/windows_game.html because I tried that but
>> outputs nothing.
>> And l would like to be in form of,
>> #{{combined_list.game_pic}}, etc
>>
>>
>> Please help me.
>> I'm Samuel
>>
>>
>>
>> --
> 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 [email protected].
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/0b3af5d4-bb40-430c-9016-c2c7fa6108fan%40googlegroups.com
> <https://groups.google.com/d/msgid/django-users/0b3af5d4-bb40-430c-9016-c2c7fa6108fan%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
>
--
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 [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-users/CAGQoQ3yPZCzzFhw9w5%3DhMrc5jWEjNQzAKgJcdCs8o6jva3JUhA%40mail.gmail.com.