summaryrefslogtreecommitdiff
path: root/archivist/model.py
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--archivist/model.py19
1 files changed, 13 insertions, 6 deletions
diff --git a/archivist/model.py b/archivist/model.py
index fd1bec3..bee6200 100644
--- a/archivist/model.py
+++ b/archivist/model.py
@@ -1,5 +1,5 @@
from peewee import *
-from playhouse.fields import CompressedField
+from playhouse.fields import CompressedField as _CompressedField
from playhouse.hybrid import *
from playhouse.sqlite_ext import SqliteExtDatabase
@@ -31,6 +31,13 @@ class BaseModel(Model):
class Meta:
database = db
+class CompressedField(_CompressedField):
+ def db_value(self, value):
+ return value if value is None else self.compress(value)
+
+ def python_value(self, value):
+ return value if value is None else self.decompress(value)
+
@table
class Document(BaseModel):
@unique
@@ -39,10 +46,11 @@ class Document(BaseModel):
OUT = 1
content = CompressedField()
- created = DateField(default=datetime.datetime.now)
+ created = DateField(default=datetime.date.today)
inserted = DateTimeField(default=datetime.datetime.now)
description = CharField(null=True)
original_path = CharField(null=True)
+ file_type = CharField(null=True)
direction = EnumField(Direction, null=True)
@classmethod
@@ -87,6 +95,7 @@ class Tag(BaseModel):
(('name', 'prefix'), True)
]
+ @property
def prefixed_name(self):
if self.prefix_id:
return "%s:%s" % (self.prefix_id, self.name)
@@ -94,12 +103,10 @@ class Tag(BaseModel):
return self.name
def __str__(self):
- description = ' -- ' + self.description if self.description else ''
-
- return self.prefixed_name() + description
+ return self.prefixed_name
def __repr__(self):
- return "<%s (#%d) %s>" % (self.__class__.__name__, self.id, self.prefixed_name())
+ return "<%s (#%d) %s>" % (self.__class__.__name__, self.id, self.prefixed_name)
@table
class DocumentTag(BaseModel):