Opened 16 years ago

Closed 16 years ago

Last modified 13 years ago

#7707 closed (duplicate)

DateField/DateTimeField `in` lookup support

Reported by: Alexander Koshelev Owned by: nobody
Component: Core (Other) Version: dev
Severity: Keywords: DateField DateTimeField lookup
Cc: Triage Stage: Unreviewed
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

ORM doesn't support 'in' lookups for DateField/DateTimeField fields.

Example from test:

class Article(models.Model):
    headline = models.CharField(max_length=100)
    pub_date = models.DateTimeField()
    class Meta:
        ordering = ('-pub_date', 'headline')

    def __unicode__(self):
        return self.headline

Article.objects.filter(pub_date__in=[datetime(2005, 7, 26), datetime(2005, 7, 28)])

And it produces wrong SQL:

('SELECT `lookup_article`.`id`, `lookup_article`.`headline`, `lookup_article`.`pub_date` FROM `lookup_article` WHERE `lookup_article`.`pub_date`
 IN (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, 
%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s,
 %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)
ORDER BY `lookup_article`.`pub_date` DESC, `lookup_article`.`headline` ASC',
 (u'[', u'd', u'a', u't', u'e',u't', u'i', u'm', u'e', u'.', u'd', u'a', u't', u'e', u't', u'i', u'm', u'e',
 u'(', u'2', u'0', u'0', u'5', u',', u' ', u'7', u',', u' ', u'2', u'6', u',', u' ', u'0', u',', u' ', u'0', u')', u',', u' ', 
u'd', u'a', u't', u'e', u't', u'i', u'm', u'e', u'.', u'd', u'a', u't', u'e', u't', u'i', u'm', u'e', u'(', u'2', 
u'0', u'0', u'5', u',', u' ', u'7', u',', u' ', u'2', u'8', u',', u' ', u'0', u',', u' ', u'0', u')', u']'))

Attachments (1)

7707.diff (1.6 KB ) - added by Alexander Koshelev 16 years ago.
path

Download all attachments as: .zip

Change History (7)

by Alexander Koshelev, 16 years ago

Attachment: 7707.diff added

path

comment:1 by Karen Tracey <kmtracey@…>, 16 years ago

Resolution: duplicate
Status: newclosed

#7448 already covers this, I believe.

comment:2 by Alexander Koshelev, 16 years ago

Resolution: duplicate
Status: closedreopened

My solution is better and has test case.

comment:3 by Karen Tracey <kmtracey@…>, 16 years ago

Resolution: duplicate
Status: reopenedclosed

And I pointed to your patch and noted it had a testcase over in #7448. There is only one problem here, we don't need multiple tickets for it. If you want to argue for your specific way of fixing the problem, please do so over in #7448.

comment:4 by Alexander Koshelev, 16 years ago

Ok. Thanks.

comment:5 by Malcolm Tredinnick, 16 years ago

(In [7883]) Fixed #7448 -- Convert "in" filters to pass in the correct values for datetimes
and similar complex objects.

Based on patches from cgrady and alexkosholev. Refs #7707.

comment:6 by Jacob, 13 years ago

milestone: 1.0

Milestone 1.0 deleted

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