Django: Ticket #12314: DateField was incorrectly handledhttps://code.djangoproject.com/ticket/12314
<p>
I followed the Django guide in creating a Polls website, and I encountered a strange, but funny bug in administration site.
</p>
<p>
The problematic model:
</p>
<pre class="wiki">class Poll(models.Model):
question = models.CharField(max_length=200)
pub_date = models.DateTimeField('date published')
def was_published_today(self):
return self.pub_date.date() == datetime.date.today()
was_published_today.short_description = "Published today?"
def __unicode__(self):
return self.question
</pre><p>
The problematic admin.py:
</p>
<pre class="wiki">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']
search_fields = ['question']
date_hierarchy = 'pub_date'
</pre><p>
What happened was, I was going through the admin guide, and it was passed midnight (well, just like now). I played around with the admin site, as I noticed something strange - a poll I added with today's date (the new day), returned False in the <em>was_published_today</em> method.
</p>
<p>
I figured something funny is going on, so I played with the date hierarchy, and strangely (but expected), the hierarchy thing did not count this Poll object as today either - in fact, I had to go back to <em>This month</em> filter to see it (I guessed the <em>Today</em> and <em>Passed 7 days</em> use a different checking method which involved subtracting as the <em>This month</em> and <em>This year</em>, just compares).
</p>
<p>
I added useful screen shots: The date can be found at the top right of the screen, and the time (fuzzily) at the bottom (thank god for KDE awesome widgets).
</p>
en-usDjangohttps://www.djangoproject.com/s/img/site/hdr_logo.gifhttps://code.djangoproject.com/ticket/12314
Trac 1.2.2toplexFri, 04 Dec 2009 23:49:07 GMTstatus changed; resolution sethttps://code.djangoproject.com/ticket/12314#comment:1
https://code.djangoproject.com/ticket/12314#comment:1
<ul>
<li><strong>status</strong>
changed from <em>new</em> to <em>closed</em>
</li>
<li><strong>resolution</strong>
set to <em>duplicate</em>
</li>
</ul>
<p>
Accidentally added two bug reports, this is the good one: <a class="closed ticket" href="https://code.djangoproject.com/ticket/12315" title="#12315: DateField incorrectly handled by administration site (closed: invalid)">#12315</a>
</p>
Ticket