In my application I do the following lookup:
my_datapoint = Datapoint.objects.filter(timestamp_lte = desired_time).reverse()[0]
I have to do this several times, for records that are not adjacent in time.
Is there a way to make this more efficient than having several separate QuerySets? Can I combine them?
This has been asked a ton of times on here. You can use
chainOne alternative to completely separate queryset objects, is to see if you can do it with “OR” queries using the
Qobjects:https://docs.djangoproject.com/en/1.4/topics/db/queries/#complex-lookups-with-q-objects
Example from the docs
This example says “objects that have a question starting with ‘Who’, AND, objects with either this pub date OR that pub date”