Opened 5 years ago

Last modified 5 years ago

#30820 closed Bug

DateRange__contains does not work as filter — at Initial Version

Reported by: henhuy Owned by:
Component: contrib.postgres Version: 2.2
Severity: Normal Keywords: postgres,
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

Having a model containing django.contrib.postgres.fields.DateRangeField I cannot filter the range by date using "contains", BUT I can get one object using "contains".

Example (my original case, is different - but this should show the error as well):

import datetime as dt
from django import models
from django.contrib.postgres.fields import DateRangeField

class Period(models.Model):

value = models.IntegerField()
period = DateRangeField()

date = dt.date(2017, 1, 1)

# This works:
period = Period.objects.get(periodcontains=date)

# This does not work:
period = Period.objects.filter(periodcontains=date).first()

SQL-Query:
SELECT "period"."id", "period"."value", "period"."period" FROM "period" WHERE "period"."period" @> (2017-01-01)::date
SQL-Error (translated from german):
FEHLER: Cannot transform Typ integer into date

There should be ' around the date, then it would work:
SELECT "period"."id", "period"."value", "period"."period" FROM "period" WHERE "period"."period" @> ('2017-01-01')::date

Don't know why getworks instead...

Change History (0)

Note: See TracTickets for help on using tickets.
Back to Top