~ferruck/idekadoh

6cda2f8f3d6207249635548aa31937392ea7f5a6 — Philipp Trommler 8 months ago 9ffb3f1
Fix entity links in models
1 files changed, 39 insertions(+), 10 deletions(-)

M idekadoh/models.py
M idekadoh/models.py => idekadoh/models.py +39 -10
@@ 1,3 1,4 @@
from enum import Enum
from flask_login import UserMixin
from werkzeug.security import check_password_hash, generate_password_hash



@@ 11,7 12,11 @@ class User(db.Model, UserMixin):
            nullable=False)
    password_hash = db.Column(db.String(128), nullable=False)
    email = db.Column(db.String(128), nullable=False)
    lists = db.relationship("List")
    lists = db.relationship('List')
    usershared = db.relationship('UserShare',
            backref='sharer',
            foreign_keys='UserShare.sharer_id')
    linkshared = db.relationship('LinkShare', backref='sharer')

    def set_password(self, plaintext):
        self.password_hash = generate_password_hash(plaintext)


@@ 59,13 64,12 @@ class List(db.Model):
    name = db.Column(db.String(128), index=True)
    created = db.Column(db.DateTime)
    last_modified = db.Column(db.DateTime)
    owner = db.Column(db.Integer,
            db.ForeignKey('user.id'),
            index=True,
            nullable=False)
    entries = db.relationship("Entry",
    owner = db.Column(db.Integer, db.ForeignKey('user.id'), index=True)
    entries = db.relationship('Entry',
            secondary=list_entry_association_table,
            backref="lists")
            backref='lists')
    usershares = db.relationship('UserShare', backref='list')
    linkshares = db.relationship('LinkShare', backref='list')

    def __repr__(self):
        return '<List {}:"{}">'.format(self.id, self.name)


@@ 74,14 78,14 @@ class List(db.Model):
class Entry(db.Model):
    id = db.Column(db.Integer, primary_key=True, autoincrement=True)
    title = db.Column(db.String(128), index=True)
    desc = db.Column(db.Text)
    description = db.Column(db.Text)
    link = db.Column(db.Text)
    img = db.Column(db.LargeBinary)
    price = db.Column(db.Float)
    comment = db.Column(db.Text)
    categories = db.relationship("Category",
    categories = db.relationship('Category',
            secondary=entry_category_association_table,
            backref="entries")
            backref='entries')

    def __repr__(self):
        return '<Entry {}:"{}">'.format(self.id, self.title)


@@ 95,3 99,28 @@ class Category(db.Model):
    def __repr__(self):
        return '<Category {}:"{}">'.format(self.id, self.name)


class ShareeType(Enum):
    guest = 1
    maintainer = 2


class UserShare(db.Model):
    id = db.Column(db.Integer, primary_key=True, autoincrement=True)
    sharer_id = db.Column(db.Integer, db.ForeignKey('user.id'))
    list_id = db.Column(db.Integer, db.ForeignKey('list.id'))
    sharee = db.Column(db.Integer, db.ForeignKey('user.id'), nullable=False)
    sharee_type = db.Column(db.Enum(ShareeType), nullable=False)

    def __repr__(self):
        return '<UserShare {}>'.format(self.id)


class LinkShare(db.Model):
    id = db.Column(db.Integer, primary_key=True, autoincrement=True)
    sharer_id = db.Column(db.Integer, db.ForeignKey('user.id'))
    list_id = db.Column(db.Integer, db.ForeignKey('list.id'))
    sharee_email = db.Column(db.String(128), nullable=False)

    def __repr__(self):
        return '<LinkShare {}>'.format(self.id)