33
This can be done using such a code:
objects = Model.objects.filter(id__in=object_ids).order_by('-timestamp')
the order_by
can be positive or negative timestamp
, depending how you want it sorted.
10
Try the following:
result = Model.objects.filter(id__in=object_ids)
This returns all Model
objects that have their id
in the given list of object_ids
. This way, you also don’t need to append additional models to the resulting QuerySet.
- [Django]-Visual Editor for Django Templates?
- [Django]-Is there a way to loop over two lists simultaneously in django?
- [Django]-Timestamp fields in django
Source:stackexchange.com