class Article(models.Model):
title = models.CharField(maxlength=64)
slug = models.SlugField(prepopulate_from=("title",))
author = models.ForeignKey(User)
text = models.TextField()
pub_date = models.DateField()
public = models.BooleanField()
def get_absolute_url(self):
return "/articles/%s/%s/" %
(self.pub_date.strftime("%Y/%m/%d"), self.slug)
I was using the date_based generic views when I noticed that something
was quite wrong. Whenever I used the archive_day or object_detail, no
results were being returned!
As an example, I created an entry in the Admin with a Date of
2006-01-16. If I went to
/articles/2006/01/
then I would see my entry in the object_list.
However, if I go to /articles/2006/01/16/ or
/articles/2006/01/16/slug, it doesn't work.
I've dug a little deeper, and got the following worrying results in the shell:
ln [14]:x = Article.objects.all()
In [15]:x.filter(pub_date__range= (datetime.datetime(2006,1,16,0,0),
datetime.datetime(2006,1,16,23,59,59,999999)))
Out[15]:[]
In [16]:x.filter(pub_date__range=
(datetime.datetime(2006,1,15,23,59,59,999999),
datetime.datetime(2006,1,16,0,0,0,0)))
Out[16]:[<Article: foo bar blah>]
That query on line 15 is the exact same query that archive_day uses.
So my article, with a pub_date of 2006-01-16 does NOT show up in the
results of the first query, but does in the second. Looks like the
comparison code somewhere is broken.
Note, I'm using sqlite3.
Jay P.
Jay P.