0b96a07 by Anon Ray at 2014-06-03 |
1 |
# -*- coding utf-8 -*- |
|
2 |
# User Management::Membership |
|
3 |
|
|
4 |
from datetime import datetime |
|
5 |
|
|
6 |
from .config import db |
|
7 |
|
|
8 |
class Membership(db.Model): |
|
9 |
""" docstring """ |
|
10 |
|
|
11 |
__tablename__ = 'memberships' |
|
12 |
|
|
13 |
id = db.Column(db.Integer, primary_key=True) |
|
14 |
uid = db.Column(db.Integer, db.ForeignKey('users.id')) |
|
15 |
gid = db.Column(db.Integer, db.ForeignKey('groups.id')) |
|
16 |
created = db.Column(db.DateTime, default=datetime.utcnow) |
|
17 |
|
|
18 |
user = db.relationship('User', backref='memberships') |
|
19 |
group = db.relationship('Group', backref='memberships') |
|
20 |
|
|
21 |
def __init__(self, user, group): |
|
22 |
self.user = user |
|
23 |
self.group = group |
|
24 |
|
|
25 |
# persist in the database |
|
26 |
def persist(self): |
|
27 |
db.session.add(self) |
|
28 |
db.session.commit() |
|
29 |
|
|
30 |
# delete from a database |
|
31 |
def remove(self): |
|
32 |
db.session.delete(self) |
|
33 |
db.session.commit() |
|
34 |
|
|
35 |
def __repr__(self): |
|
36 |
return'<Membership %d>' % self.uid |
|
37 |
|