Opened 16 years ago

Closed 16 years ago

Last modified 13 years ago

#8214 closed (fixed)

Filtering a date/time field omits results.

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

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 Amy Farrell 16 years ago.
_sqlite_extract returns unicode (not integer) in all cases, fixes failing compare

Download all attachments as: .zip

Change History (9)

comment:1 by Jacob, 16 years ago

milestone: 1.0
Triage Stage: UnreviewedAccepted

comment:2 by mattbaker, 16 years ago

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 by mattbaker, 16 years ago

Wow, sorry for the ugly formatting *sigh*

by Amy Farrell, 16 years ago

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

comment:4 by Amy Farrell, 16 years ago

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

comment:5 by Amy Farrell, 16 years ago

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 by James Bennett, 16 years ago

#8416 was closed as a duplicate.

comment:7 by Malcolm Tredinnick, 16 years ago

Resolution: fixed
Status: newclosed

(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 by Jacob, 13 years ago

milestone: 1.0

Milestone 1.0 deleted

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