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