diff --git a/anki/models.py b/anki/models.py index 350901a93..7a3cf34d8 100644 --- a/anki/models.py +++ b/anki/models.py @@ -65,20 +65,22 @@ class Model(object): else: self.id = None self.name = u"" - self.mod = intTime() + self.crt = intTime() + self.mod = self.crt self.conf = defaultConf.copy() self.css = "" self.fields = [] self.templates = [] def load(self): - (self.mod, + (self.crt, + self.mod, self.name, self.fields, self.templates, self.conf, self.css) = self.deck.db.first(""" -select mod, name, flds, tmpls, conf, css from models where id = ?""", self.id) +select crt, mod, name, flds, tmpls, conf, css from models where id = ?""", self.id) self.fields = simplejson.loads(self.fields) self.templates = simplejson.loads(self.templates) self.conf = simplejson.loads(self.conf) @@ -87,8 +89,8 @@ select mod, name, flds, tmpls, conf, css from models where id = ?""", self.id) self.mod = intTime() self.css = self.genCSS() ret = self.deck.db.execute(""" -insert or replace into models values (?, ?, ?, ?, ?, ?, ?)""", - self.id, self.mod, self.name, +insert or replace into models values (?, ?, ?, ?, ?, ?, ?, ?)""", + self.id, self.crt, self.mod, self.name, simplejson.dumps(self.fields), simplejson.dumps(self.templates), simplejson.dumps(self.conf), diff --git a/anki/storage.py b/anki/storage.py index 644a076f0..d8def5625 100644 --- a/anki/storage.py +++ b/anki/storage.py @@ -111,6 +111,7 @@ create table if not exists fsums ( create table if not exists models ( id integer primary key, + crt integer not null, mod integer not null, name text not null, flds text not null, @@ -314,7 +315,7 @@ from facts order by created""") import anki.models _moveTable(db, "models") db.execute(""" -insert into models select id, cast(modified as int), +insert into models select id, cast(created as int), cast(modified as int), name, "{}", "{}", ?, "" from models2""", simplejson.dumps( anki.models.defaultConf)) db.execute("drop table models2")