Code

Opened 6 years ago

Closed 6 years ago

Last modified 3 years ago

#7707 closed (duplicate)

DateField/DateTimeField `in` lookup support

Reported by: alexkoshelev 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 alexkoshelev 6 years ago.
path

Download all attachments as: .zip

Change History (7)

Changed 6 years ago by alexkoshelev

path

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

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Resolution set to duplicate
  • Status changed from new to closed

#7448 already covers this, I believe.

comment:2 Changed 6 years ago by alexkoshelev

  • Resolution duplicate deleted
  • Status changed from closed to reopened

My solution is better and has test case.

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

  • Resolution set to duplicate
  • Status changed from reopened to closed

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 6 years ago by alexkoshelev

Ok. Thanks.

comment:5 Changed 6 years ago by mtredinnick

(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 3 years ago by jacob

  • milestone 1.0 deleted

Milestone 1.0 deleted

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.