aboutsummaryrefslogtreecommitdiff
path: root/wqflask/wqflask/model.py
diff options
context:
space:
mode:
authorSam2013-10-30 19:53:09 -0500
committerSam2013-10-30 19:53:09 -0500
commit74d803b0de60edf324b1a6ce589d12a055ef312b (patch)
treef14022873a7f898e7b9258b01a0ac1a9c30a2cdf /wqflask/wqflask/model.py
parentde7abc1d2ac9fef87796baa7330cbaaaadbbec2a (diff)
downloadgenenetwork2-74d803b0de60edf324b1a6ce589d12a055ef312b.tar.gz
More work on collections
Diffstat (limited to 'wqflask/wqflask/model.py')
-rw-r--r--wqflask/wqflask/model.py12
1 files changed, 10 insertions, 2 deletions
diff --git a/wqflask/wqflask/model.py b/wqflask/wqflask/model.py
index c1ad0a78..cf9e58e1 100644
--- a/wqflask/wqflask/model.py
+++ b/wqflask/wqflask/model.py
@@ -10,7 +10,8 @@ from flask.ext.sqlalchemy import SQLAlchemy
from wqflask import app
-from sqlalchemy import Column, Integer, String, Table, ForeignKey, Unicode, Boolean, DateTime, Text
+from sqlalchemy import (Column, Integer, String, Table, ForeignKey, Unicode, Boolean, DateTime,
+ Text, Index)
from sqlalchemy.orm import relationship, backref
from wqflask.database import Base, init_db
@@ -98,10 +99,17 @@ class UserCollection(Base):
__tablename__ = "user_collection"
id = Column(Unicode(36), primary_key=True, default=lambda: unicode(uuid.uuid4()))
user = Column(Unicode(36), ForeignKey('user.id'))
- name = Column(Text)
+
+ # I'd prefer this to not have a length, but for the index below it needs one
+ name = Column(Unicode(50))
created_timestamp = Column(DateTime(), default=lambda: datetime.datetime.utcnow())
changed_timestamp = Column(DateTime(), default=lambda: datetime.datetime.utcnow())
members = Column(Text) # We're going to store them as a json list
# This index ensures a user doesn't have more than one collection with the same name
__table_args__ = (Index('usercollection_index', "user", "name"), )
+
+ @property
+ def num_members(self):
+ print("members are:", json.loads(self.members))
+ return len(json.loads(self.members))