Opened 15 years ago
Closed 15 years ago
#11851 closed (duplicate)
.annotate() turns datetime fields to unicode with sqlite3
Reported by: | aminc | Owned by: | nobody |
---|---|---|---|
Component: | Database layer (models, ORM) | Version: | 1.1 |
Severity: | Keywords: | ||
Cc: | Triage Stage: | Unreviewed | |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
I have two models, joined with a ManyToManyField:
class MainModel(models.Model): date = models.DateTimeField(auto_now_add=True) others = models.ManyToManyField('OtherModel') class OtherModel(models.Model): pass
I set up a sample dataset:
>>> m = MainModel.objects.create() >>> for i in range(12): >>> ... m.others.create()
But when I use queryset annotation, my DateTimeField is giving me the raw unicode value:
>>> MainModel.objects.annotate(num_others=Count('others')).get().date u'2009-09-08 12:54:17.380000' >>> MainModel.objects.get().date datetime.datetime(2009, 9, 8, 12, 54, 17, 380000)
These are my sqlite tables:
sqlite> .schema news_mainmodel CREATE TABLE "news_mainmodel" ( "id" integer NOT NULL PRIMARY KEY, "date" datetime NOT NULL ); sqlite> .schema news_othermodel CREATE TABLE "news_othermodel" ( "id" integer NOT NULL PRIMARY KEY );
Change History (2)
comment:1 by , 15 years ago
comment:2 by , 15 years ago
Resolution: | → duplicate |
---|---|
Status: | new → closed |
This behavior is due to a bug in sqlite3, see #10031. You need to upgrade to a more recent level of sqlite.
Note:
See TracTickets
for help on using tickets.
Just for completeness, here is the join table. All three were created using syncdb.