Monday, February 27, 2023

Re: Getting 4 four latest objects from django model

latest[1] always returns the singular latest object. Use order_by to return multiple objects.


On February 27, 2023 2:51:58 AM CST, Byansi Samuel <> wrote:

I got a problem with my queryset. Am trying to get 4 latest objects from my model but it returns  1 objects  the top latest.

Below is my code. Any support and guidance is appreciated.


from  Action.models import ActionGame

latest_action= [ActionGame.objects.filter (os='windows', category='action').latest ('published_date')][:4]

Buy the problem is that it returns 1 object yet l need 4 objects

What  can I do to solve it?

No comments:

Post a Comment