Opened 9 years ago

Closed 14 months ago

#6439 closed New feature (duplicate)

support for filter methods on date field attributes

Reported by: omat@… Owned by: nobody
Component: Database layer (models, ORM) Version: master
Severity: Normal Keywords: datefield, database api, filter methods
Cc: ross@… Triage Stage: Accepted
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

Exact matches on date field attributes such as:

filter(datefield__month=1)

are supported. For consistency, I think all filter methods on attributes such as:

filter(datefield__month__in=[1, 2, 3])

should also be supported.

OMat

Change History (6)

comment:1 Changed 9 years ago by Chris Beaven

Needs documentation: unset
Needs tests: unset
Patch needs improvement: unset
Triage Stage: UnreviewedDesign decision needed

comment:2 Changed 8 years ago by Ross Poulton

Cc: ross@… added

FWIW I've just encountered this today trying to use this:

class Event(models.Model):
    title = models.CharField(max_length=100)
    event_date = models.DateField()

e = Event(title='My First Event', event_date=date(2008, 08, 01))
e.save()
e2 = Event(title='Second Event', event_date=date(2008, 08, 12))
e2.save()
# Events that happen on or before the 8th of every month: Expect to only get 'My First Event'.
# This will raise: FieldError: Join on field 'event_date' not permitted.
events = Event.objects.filter(event_date__day__lte=8)

comment:3 Changed 6 years ago by Julien Phalip

Type: New feature

comment:4 Changed 5 years ago by Julien Phalip

Severity: Normal

comment:5 Changed 5 years ago by Alex Gaynor

Easy pickings: unset
Triage Stage: Design decision neededAccepted
UI/UX: unset

Accepted, though I think it's a dude of another ticket. Really this is representative of a large issue about fields defining their own lookups, and chaining those. But I don't know the dupe's #, so I'll let this be open.

comment:6 Changed 14 months ago by Tim Graham

Resolution: duplicate
Status: newclosed

Fixed by #9596 in Django 1.9.filter. Sytanx is (datefield__date__month__in=[1, 2, 3])

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