summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--app/python/rcal/model.py27
1 files changed, 25 insertions, 2 deletions
diff --git a/app/python/rcal/model.py b/app/python/rcal/model.py
index 94e426f..705fba2 100644
--- a/app/python/rcal/model.py
+++ b/app/python/rcal/model.py
@@ -1,5 +1,5 @@
# pylint: disable=too-few-public-methods, invalid-name
-from sqlalchemy import Column, ForeignKey
+from sqlalchemy import Column, ForeignKey, Table
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm import relationship
from sqlalchemy.types import (TIMESTAMP, Boolean, DateTime, Integer, String,
@@ -8,6 +8,7 @@ from sqlalchemy.types import (TIMESTAMP, Boolean, DateTime, Integer, String,
from dateutil.tz import tzutc
+# pylint: disable=abstract-method, unused-argument
class UTCDateTime(TypeDecorator):
impl = DateTime
@@ -119,4 +120,26 @@ class Category(BASE):
session.add(category)
return category
-__all__ = ('Calendar', 'Entry', 'Category')
+
+user_selections = Table(
+ 'user_selections', BASE.metadata,
+ Column('_user', Integer,
+ ForeignKey('users.id', onupdate='CASCADE', ondelete='CASCADE')),
+ Column('_calendar', String(255),
+ ForeignKey('calendars.uid', onupdate='CASCADE', ondelete='CASCADE'))
+)
+
+
+class User(BASE):
+ __tablename__ = 'users'
+
+ id = Column(Integer, primary_key=True)
+ login = Column(String(255), unique=True, index=True)
+ password = Column(String(255))
+ is_admin = Column(Boolean)
+ last_login = Column(UTCDateTime)
+
+ calendars = relationship('Calendar',
+ secondary=user_selections)
+
+__all__ = ('Calendar', 'Entry', 'Category', 'User')