Opened 8 years ago

Closed 8 years ago

Last modified 5 years ago

#7707 closed (duplicate)

DateField/DateTimeField `in` lookup support

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

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 8 years ago.
path

Download all attachments as: .zip

Change History (7)

Changed 8 years ago by Alexander Koshelev

Attachment: 7707.diff added

path

comment:1 Changed 8 years ago by Karen Tracey <kmtracey@…>

Resolution: duplicate
Status: newclosed

#7448 already covers this, I believe.

comment:2 Changed 8 years ago by Alexander Koshelev

Resolution: duplicate
Status: closedreopened

My solution is better and has test case.

comment:3 Changed 8 years ago by Karen Tracey <kmtracey@…>

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 Changed 8 years ago by Alexander Koshelev

Ok. Thanks.

comment:5 Changed 8 years ago by Malcolm Tredinnick

(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 Changed 5 years ago by Jacob

milestone: 1.0

Milestone 1.0 deleted

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