How To Latest Objects Created In Django Models By Similar Field Value?
I have created an app here people can upload 'csv' files of their items details to the server, and then perform various opertaions upon it. But, because every item has it's own uni
Solution 1:
For what i could understand from your question, you maybe need this (withouth testing it). Disable and enable USE_TZ if its True in settings.py.
latest_item = ItemBatch.objects.latest('time')
from django.conf import settings
settings.USE_TZ = False
latest_items = ItemBatch.objects.filter(time__date=latest_item.time.date(), time__hour=latest_item.time.hour, time__minute=latest_item.time.minute)
settings.USE_TZ = True
'latest_items' contains all elements that match the date, hour and minute as the latest ItemBatch object. Add second too if you want it, but it may not work if there are lots of elements added in the same time.
Post a Comment for "How To Latest Objects Created In Django Models By Similar Field Value?"