Issue #14 new

querying with timedelta fields seems not to work (on sqlite)

Hans-Peter Locher
created an issue

Filtering for this field in combination with Datetime seems not to work, at least using sqlite.

my model looks as follows:

class Event(models.Model):

    start_date = models.DateTimeField()
    duration = TimedeltaField(null=True, blank=True)

I want to make a query for all events that are starting in the future, or are still running, like so:

now = datetime.datetime.now() # 2013-06-04
events = Event.objects.exclude(start_date__lt=now-F('duration'))

for x in events: 
    print x.start_date, x.duration

result:

2013-04-12 22:00:00 2 days, 0:00:00 2013-03-15 22:00:00 4:00:00 2013-12-28 20:00:00 1 day, 0:00:00 2013-06-03 06:00:00 2 days, 0:00:00

Comments (2)

  1. Hans-Peter Locher reporter

    Tested same code with postgresql db and it works. Obviously the lack of sqlite-INTERVAL is the reason here. So this is no issue of django-timedelta.

    If you need queries - use postgres :)

  2. Matthew Schinckel repo owner

    I'd be interested to see what the SQL that gets generated by that query is.

    (But, given I develop exclusively on postgres, I'm unlikely to have the desire to fix it. I will accept patches if you can come up with a solution).

  3. Log in to comment