Incorrect date order in django template

I get a list of objects like this

return Post.objects.filter(categoria=categoria)

And I send this to the template. I show them in the template as follows

{% for p in posts reversed %}

Thus, I get new messages from above. It works in about 99% of cases, but it doesn’t work randomly if it shows the last message below a senior post. The dates are correct, the last message shows that it has the latest date, but it appears below some other old messages.

Nothing special happens when it fails, I think it might be some kind of obscure bug in Django.

Any ideas on what could be causing this?

+3
source share
2 answers

.order_by(...) , ordering Meta:

class Post(Model):
    # your fields here
    the_date = DateTimeField(...)

    class Meta:
        # sort by "the date" in descending order unless
        # overridden in the query with order_by()
        ordering = ['-the_date']
+13

order_by , , .

-1

All Articles