Opened 7 years ago

Closed 7 years ago

Last modified 4 years ago

#8214 closed (fixed)

Filtering a date/time field omits results.

Reported by: redwyrm Owned by: nobody
Component: contrib.admin Version: master
Severity: Keywords: aug22sprint
Cc: Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: yes Patch needs improvement: no
Easy pickings: UI/UX:

Description

If the pub_date of an poll is today, then it ought to show up when I click Today or This month, but it isn't. It only shows up when I click Any date, Past 7 days, or This year.

My Poll model:

class Poll(models.Model):
    question = models.CharField(max_length=200)
    pub_date = models.DateTimeField('date published')
    #...

And my PollAdmin model:

class PollAdmin(admin.ModelAdmin):
    fieldsets = [
        (None, {'fields': ['question']}),
        ('Date information', {'fields': ['pub_date'], 'classes': ['collapse']}),
    ]
    inlines = [ChoiceInline]
    list_display = ('question', 'pub_date', 'was_published_today')
    list_filter = ['pub_date']

admin.site.register(Poll, PollAdmin)

Current date is August 10th, 2008...
Screenshot when filtering by "Any date": http://i38.tinypic.com/ayzdf.jpg
Screenshot when filtering by "Today": http://i33.tinypic.com/2342ut.png

My database backend is SQLite3.

Attachments (1)

ticket_8214_fix_type_of_datetime_extract.patch (476 bytes) - added by akfarrell 7 years ago.
_sqlite_extract returns unicode (not integer) in all cases, fixes failing compare

Download all attachments as: .zip

Change History (9)

comment:1 Changed 7 years ago by jacob

  • milestone set to 1.0
  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Triage Stage changed from Unreviewed to Accepted

comment:2 Changed 7 years ago by mattbaker

When you pass unicode strings to filter(dateyear=x) you end up with 0 results, made a quick hack to filter that iterated through and int()ed the unicode strings and everything works as expected.

Adventuring off to dig further...

comment:3 Changed 7 years ago by mattbaker

Wow, sorry for the ugly formatting *sigh*

Changed 7 years ago by akfarrell

_sqlite_extract returns unicode (not integer) in all cases, fixes failing compare

comment:4 Changed 7 years ago by akfarrell

  • Has patch set
  • Keywords aug22sprint added
  • Needs tests set

comment:5 Changed 7 years ago by akfarrell

Found that _sqlite_extract (see patch) was returning an integer for month, causing the filter to fail. This was introduced in ChangeSet 8131, which removed str() around the return value. We added unicode(). No one involved is a regular maintainer, so this needs review.

comment:6 Changed 7 years ago by ubernostrum

#8416 was closed as a duplicate.

comment:7 Changed 7 years ago by mtredinnick

  • Resolution set to fixed
  • Status changed from new to closed

(In [8494]) Fixed #8214 -- Added back a stringification that was dropped during [8131].
This restores filtering on dates in the admin, for example. Thanks to akfarrell
and a small team of workers at the Portland Sprint.

comment:8 Changed 4 years ago by jacob

  • milestone 1.0 deleted

Milestone 1.0 deleted

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