[Answer]-Short record query with Django ORM

1👍

✅

queryset.filter(to_date__gt=from_date, from_date__lt=to_date)

That is, to be returned the event must end after the new event starts and must start before the new event ends. Anything that ends before the new from_date is not returned, neither is anything that doesn’t start until after it ends.

That does not precisely match your original query, but it does match the behavior described in the comments for when there’s a record in the database that is entirely within the range set by the new dates.

Leave a comment