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