[Answered ]-Django – order queryset result by update time of instances

2πŸ‘

βœ…

You will need to add a timestamp field to your model. For example in my own code I add a date_updated field for this very purpose.

Your custom models don’t have this by default so you have to add it.

last_edit = models.DateTimeField(auto_now_add=True)

You will have to update this in the save method (or another method) of your model.

import datetime
self.last_edit = datetime.datetime.now()
πŸ‘€mugurm

0πŸ‘

If you have a field on your model that tracks this update time (more information on this here), then yes, you can just use that in a normal ordering specification.

If you don’t track updates on your model, no, that is not possible.

Leave a comment