This file looks large and may slow your browser down if we attempt
to syntax highlight it, so we are showing it without any
pretty colors.
Highlight
it anyway.
1 |
# -*- coding utf-8 -*- |
2 |
# User Management::Membership |
3 |
|
4 |
from datetime import datetime |
5 |
|
6 |
from swtstore.classes.database import db |
7 |
|
8 |
|
9 |
class Membership(db.Model): |
10 |
""" docstring """ |
11 |
|
12 |
__tablename__ = 'memberships' |
13 |
|
14 |
id = db.Column(db.Integer, primary_key=True) |
15 |
uid = db.Column(db.Integer, db.ForeignKey('users.id')) |
16 |
gid = db.Column(db.Integer, db.ForeignKey('groups.id')) |
17 |
created = db.Column(db.DateTime, default=datetime.utcnow) |
18 |
|
19 |
user = db.relationship('User', backref='memberships') |
20 |
group = db.relationship('Group', backref='memberships') |
21 |
|
22 |
def __init__(self, user, group): |
23 |
self.user = user |
24 |
self.group = group |
25 |
|
26 |
# persist in the database |
27 |
def persist(self): |
28 |
db.session.add(self) |
29 |
db.session.commit() |
30 |
|
31 |
# delete from a database |
32 |
def remove(self): |
33 |
db.session.delete(self) |
34 |
db.session.commit() |
35 |
|
36 |
def __repr__(self): |
37 |
return'<Membership %d>' % self.uid |