예제 #1
0
class Follow(db.Model):
    id = db.Column(db.Integer, autoincrement=True, primary_key=True)
    init_id = db.Column(db.Integer, db.ForeignKey('user.id'))
    respond_id = db.Column(db.Integer, db.ForeignKey('user.id'))

    init = db.relationship('User', foreign_keys=[init_id])
    respond = db.relationship('User', foreign_keys=[respond_id])
예제 #2
0
class User(UserMixin, db.Model):
    """ модель пользователя """
    
    id = db.Column(db.Integer, primary_key=True)
    email = db.Column(db.String(50), unique=True, nullable=False)
    password = db.Column(db.String(100), nullable=False)
    name = db.Column(db.String(254), nullable=False)

    roles = db.relationship('Role', secondary=roles_users,
                            backref=db.backref('users', lazy='dynamic'))

    user_client = db.relationship('UserClient', backref='user_client')
    
    def __init__(self, **kwargs):
        self.email = kwargs.get('email')
        self.name = kwargs.get('name')
        self.password = bcrypt.hash(kwargs.get('password'))

    @classmethod
    def authenticate(cls, email, password):
        user = cls.query.filter(cls.email == email).one()
        
        if not bcrypt.verify(password, user.password):
            raise Exception('Invalid password')
        return user
예제 #3
0
파일: models.py 프로젝트: zcastle/api_ww
class Guia(db.Model):
    igui_id = db.Column(db.Integer, primary_key=True)
    dgui_fee = db.Column(db.DateTime)
    cgui_ser = db.Column(db.String(3))
    cgui_num = db.Column(db.String(11))
    icli_id = db.Column(db.Integer, db.ForeignKey("contacto.id"))
    contacto = db.relationship("Contacto",
                               backref=db.backref('guia', lazy='dynamic'))

    tipo_id = db.Column(db.Integer, db.ForeignKey("guia_tipo.id"))
    tipo = db.relationship("GuiaTipo",
                           backref=db.backref("guia", lazy="dynamic"))

    cia_id = db.Column(db.Integer, db.ForeignKey("cia.id"))

    cerrado = db.Column(db.Integer)
    vgui_est = db.Column(db.String(11))

    def __repr__(self):
        return '<Guia %r-%r>' % (self.cgui_ser, self.cgui_num)

    def getNumero(self):
        if self.cerrado == 0:
            return "EN PROCESO"
        else:
            return '%s-%s' % (self.cgui_ser, self.cgui_num)

    def getFecha(self):
        return self.dgui_fee.strftime('%d-%m-%Y')

    def isAnulado(self):
        return "N" if self.vgui_est == "GENERADO" else "S"
예제 #4
0
class Path(PkModel):

    __tablename__ = "paths"
    slug = db.Column(db.String(200), nullable=False)
    title = db.Column(db.String(200), nullable=False)
    sections = db.relationship("Section",
                               backref="section_path",
                               lazy=True,
                               cascade="all, delete-orphan")

    user_id = db.Column(db.Integer, db.ForeignKey("users.id"), nullable=False)
    is_visible = db.Column(db.Boolean, default=True)

    like_list = db.relationship("LikeList",
                                backref="like_list_path",
                                lazy=True,
                                uselist=False)
    bookmark_list = db.relationship("BookmarkList",
                                    backref="bookmark_list_path",
                                    lazy=True,
                                    uselist=False)

    def get_url(self):
        return url_for("www.path",
                       username=self.path_user.username,
                       path_slug=self.slug)
예제 #5
0
파일: models.py 프로젝트: zcastle/api_ww
class Producto(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    serie = db.Column(db.String(255), unique=True)
    familia_id = db.Column(db.Integer, db.ForeignKey("familia.id"))
    familia = db.relationship("Familia",
                              backref=db.backref("producto", lazy="dynamic"))
    marca_id = db.Column(db.Integer, db.ForeignKey("marca.id"))
    marca = db.relationship("Marca",
                            backref=db.backref("producto", lazy="dynamic"))
    modelo_id = db.Column(db.Integer, db.ForeignKey("modelo.id"))
    modelo = db.relationship("Modelo",
                             backref=db.backref("producto", lazy="dynamic"))
    tipo_id = db.Column(db.Integer, db.ForeignKey("tipo_producto.id"))
    tipo = db.relationship("TipoProducto",
                           backref=db.backref("producto", lazy="dynamic"))
    guia_id = db.Column(db.Integer, db.ForeignKey("guia.igui_id"))
    guia = db.relationship("Guia",
                           backref=db.backref("producto", lazy="dynamic"))
    producto_id = db.Column(db.Integer)
    #producto_id = db.Column(db.Integer, db.ForeignKey("producto.id"))
    #producto = db.relationship("Producto", backref=db.backref("producto", lazy="dynamic"))
    capacidad = db.Column(db.String(255))

    def __repr__(self):
        return "<Producto %r>" % self.serie
예제 #6
0
class Ratings(db.Model):
    user_id = db.Column(db.Integer, db.ForeignKey('user.id'), primary_key=True)
    joke_id = db.Column(db.Integer, db.ForeignKey('joke.id'), primary_key=True)
    rating = db.Column(db.String(50))
    created_at = db.Column(db.DateTime,
                           nullable=False,
                           default=datetime.utcnow)
    user = db.relationship("User", back_populates="jokes")
    joke = db.relationship("Joke", back_populates="users")
예제 #7
0
class User(db.Model):
  id = db.Column(db.Integer, primary_key=True)
  name = db.Column(db.String(100))
  age = db.Column(db.Integer)
  profile = db.relationship('UserProfile', backref='user', cascade="all, delete-orphan",uselist=False) 
  organisation = db.relationship('Organisation', backref='user', cascade="all, delete-orphan", lazy='dynamic') 

  def __init__(self, name, age,):
    self.name = name
    self.age = age
예제 #8
0
class User(db.Model):
    """
    This class corresponds to the database model for a User object.
    A high level interface that allows more efficient interactions with the relational database.
    """
    __tablename__ = 'Users'
    __searchable__ = [
        'username', 'first_name', 'last_name', 'email', 'school', 'state'
    ]

    first_name = db.Column(db.String(64), index=True, nullable=False)
    last_name = db.Column(db.String(64), index=True, nullable=False)
    username = db.Column(db.String(64),
                         index=True,
                         primary_key=True,
                         unique=True,
                         nullable=False)
    email = db.Column(db.String(120), index=True, unique=True, nullable=False)
    password = db.Column(db.String(128), nullable=False)
    school = db.Column(db.String(128))
    grade = db.Column(db.String(64))
    state = db.Column(db.String(64))
    post_time = db.Column(db.DateTime,
                          index=True,
                          default=datetime.utcnow,
                          nullable=False)
    forum_questions = db.relationship("ForumQuestion",
                                      backref='author',
                                      lazy='dynamic')
    forum_posts = db.relationship("ForumPost",
                                  backref='author',
                                  lazy='dynamic')
    user_posts = db.relationship("UserPost", backref='author', lazy='dynamic')
    authenticated = db.Column(db.Boolean, default=False)

    def is_active(self):
        return True

    def get_id(self):
        return self.username

    def is_authenticated(self):
        return self.authenticated

    def is_anonymous(self):
        return False

    def __repr__(self):
        return '<User {}>'.format(self.username)

    def test_password(self, password):
        if password == self.password:
            return True
        return False
예제 #9
0
class Follow(db.Model):
    id = db.Column(db.Integer, primary_key=True, autoincrement=True)
    follower_id = db.Column(db.Integer, db.ForeignKey('user.id'))
    follower = db.relationship('User', primaryjoin=follower_id == User.id)

    followee_id = db.Column(db.Integer, db.ForeignKey('user.id'))
    followee = db.relationship('User', primaryjoin=followee_id == User.id)

    def __init__(self, follower_id, followee_id):
        self.follower_id = follower_id
        self.followee_id = followee_id
예제 #10
0
class Post(db.Model):
    __tablename__ = 'post'
    id = db.Column(db.Integer, primary_key=True)
    post = db.Column(db.String(10000))
    timestamp = db.Column(db.DateTime, index=True, default=datetime.utcnow)
    user_id = db.Column(db.Integer, db.ForeignKey('user.id'))
    likes = db.relationship('PostLike', backref='post', lazy='dynamic')
    dislikes = db.relationship('PostDislike', backref='post', lazy='dynamic')

    def __repr__(self):
        return '<Post likes {}>'.format(self.likes.all())
예제 #11
0
class AssetModel(db.Model):
    """
    AssetModel represents an asset in the metadata database.
    """
    __tablename__ = 'assets'
    user_id = db.Column(db.Integer, nullable=False)
    asset_id = db.Column(db.Integer, primary_key=True)
    gitlab_id = db.Column(db.Integer, nullable=False)
    asset_name = db.Column(db.String(255), unique=True)
    description = db.Column(db.String(255))
    image_url = db.Column(db.String(255))
    cloud_services = db.relationship('CsModel', backref='AssetModel')
    industries = db.relationship('IndustryModel', backref='AssetModel')
예제 #12
0
파일: models.py 프로젝트: zcastle/api_ww
class GuiaSalidaDetalle(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    guia_id = db.Column(db.Integer, db.ForeignKey("guia.igui_id"))
    guia = db.relationship("Guia",
                           backref=db.backref('guia_salida_detalle',
                                              lazy='dynamic'))
    producto_id = db.Column(db.Integer, db.ForeignKey("producto.id"))
    producto = db.relationship("Producto",
                               backref=db.backref('guia_salida_detalle',
                                                  lazy='dynamic'))
    cantidad = db.Column(db.Integer)

    def __repr__(self):
        return '<GuiaSalidaDetalle %r>' % (self.id)
예제 #13
0
파일: models.py 프로젝트: zcastle/api_ww
class DetalleCompra(db.Model):
    idco_id = db.Column(db.Integer, primary_key=True)
    icom_id = db.Column(db.Integer, db.ForeignKey("compra.icom_id"))
    compra = db.relationship("Compra",
                             backref=db.backref("detalle_compra",
                                                lazy="joined"))

    iins_id = db.Column(db.Integer, db.ForeignKey("producto.id"))
    producto = db.relationship("Producto",
                               backref=db.backref("detalle_compra",
                                                  lazy="joined"))

    def __repr__(self):
        return '<DetalleCompra %r>' % self.idco_id
예제 #14
0
파일: models.py 프로젝트: arrinn/TestsForum
class Users(db.Model, UserMixin):
    id = db.Column(db.Integer, primary_key=True)
    username = db.Column(db.String(64), index=True, unique=True)
    email = db.Column(db.String(120), index=True, unique=True)
    password_hash = db.Column(db.String(128))
    score = db.Column(db.Float)
    answers = db.relationship('Answers', backref='answered', lazy='dynamic')
    questions = db.relationship('Questions', backref='created', lazy='dynamic')

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

    def check_password(self, password):
        return check_password_hash(self.password_hash, password)
예제 #15
0
class Surveyresponse(db.Model):

    surveyResponseID = db.Column(db.Integer,
                                 autoincrement=True,
                                 primary_key=True)
    surveyName = db.Column(db.String(100), nullable=True)
    surveyID = db.Column(db.Integer,
                         db.ForeignKey('survey.surveyID'),
                         nullable=False)
    studentID = db.Column(db.Integer,
                          db.ForeignKey('user.userID'),
                          nullable=False)
    user = db.relationship('User', backref='response_student')

    def __repr__(self):
        return f"SurveyResponse('{self.surveyResponseID}')"

    def get_response_id(self):
        return '{}'.format(self.surveyResponseID)

    def get_survey_id(self):
        return '{}'.format(self.surveyID)

    def get_survey_name(self):
        return '{}'.format(self.surveyName)

    def get_student_id(self):
        return '{}'.format(self.studentID)
예제 #16
0
class Question(db.Model):

    questionID = db.Column(db.Integer, autoincrement=True, primary_key=True)
    label = db.Column(db.String(64))
    type = db.Column(db.String(10), nullable=False)
    repetition = db.Column(db.String(15))
    content = db.Column(db.String(300), nullable=True)
    surveyID = db.Column(db.Integer,
                         db.ForeignKey('survey.surveyID'),
                         nullable=False)
    survey = db.relationship('Survey', backref='survey_questions')

    def __repr__(self):
        return f"Question('{self.questionID}','{self.type}','{self.repetition}','{self.content}','{self.surveyID}')"

    def get_id(self):
        return '{}'.format(self.questionID)

    def get_survey_id(self):
        return '{}'.format(self.surveyID)

    def get_label(self):
        return '{}'.format(self.label)

    def get_type(self):
        return '{}'.format(self.type)

    def get_repetition(self):
        return '{}'.format(self.repetition)

    def get_content(self):
        return '{}'.format(self.content)
예제 #17
0
class Survey(db.Model):

    surveyID = db.Column(db.Integer, autoincrement=True, primary_key=True)
    instructorName = db.Column(db.String(64), nullable=False)
    name = db.Column(db.String(64), nullable=False)
    date = db.Column(db.DateTime, nullable=False, default=datetime.utcnow)
    instructorID = db.Column(db.Integer,
                             db.ForeignKey('instructor.instructorID'),
                             nullable=False)
    instructor = db.relationship('Instructor', backref='survey_instructor')

    def __repr__(self):
        return f"Survey('{self.instructorName}','{self.name})'"

    def get_id(self):
        return '{}'.format(self.surveyID)

    def get_instructor(self):
        return '{}'.format(self.instructorName)

    def get_name(self):
        return '{}'.format(self.name)

    def get_date(self):
        return '{}'.format(self.date)
예제 #18
0
class ExternalPrice(Common, db.Model):
    """公司/单位专价模型"""
    __tablename__ = 'external_price'
    id = db.Column(db.Integer, index=True, primary_key=True)

    product_id = db.Column(db.Integer,
                           db.ForeignKey('product.id'),
                           nullable=False)
    company_id = db.Column(db.Integer,
                           db.ForeignKey('firm.id'),
                           nullable=False)
    price = db.Column(db.DECIMAL(precision=9, decimal_return_scale=2),
                      default=0.00,
                      nullable=False,
                      comment='产品单价')
    unit_id = db.Column(db.SMALLINT,
                        db.ForeignKey('product_unit.id'),
                        nullable=False,
                        comment='产品单位ID')
    unit = db.relationship('ProductUnit', lazy='select')

    def __init__(self, product_id: int, company_id: int, price: float,
                 unit_id: int):
        self.product_id = product_id
        self.company_id = company_id
        self.price = price
        self.unit_id = unit_id
예제 #19
0
class Conf(PkModel):
    __tablename__ = 'conferences'
    year = db.Column(db.Integer, info={'label': 'Year'}, nullable=False)
    cfp_start = db.Column(db.Date, info={'label': 'CFP Start'}, nullable=False)
    cfp_end = db.Column(db.Date, info={'label': 'CFP End'}, nullable=False)

    talks = db.relationship('Talk',
                            backref=db.backref('talk_conference', lazy=True))

    reviewer_list = db.relationship("ReviewerList",
                                    backref="reviewer_list_conf",
                                    lazy=True,
                                    uselist=False)

    def __repr__(self):
        return 'conf:{}'.format(self.year)
예제 #20
0
class User(UserMixin, db.Model):
    __tablename__ = 'users'
    id = db.Column(db.Integer, primary_key=True)
    email = db.Column(db.String(100))
    password = db.Column(db.String(128))
    name = db.Column(db.String(120))
    role = db.Column(db.String(120))

    files = db.relationship('File', backref='owner', lazy=True,
        cascade="all, delete, delete-orphan")

    def set_hash(self, password):
        self.password = generate_password_hash(password, method="sha256")

    def check_hash(self, password):
        return check_password_hash(self.password, password)

    def insert(self):
        db.session.add(self)
        db.session.commit()

    def update(self):
        db.session.commit()

    def delete(self):
        db.session.delete(self)
        db.session.commit()
예제 #21
0
class Subject(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(80), unique=True, nullable=False)
    lessons = db.relationship('Lesson', backref='subject')

    def __repr__(self):
        return '<Subject %r>' % self.name
예제 #22
0
class Optionresponse(db.Model):
    optionResponseID = db.Column(db.Integer,
                                 autoincrement=True,
                                 primary_key=True)
    content = db.Column(db.Integer, nullable=False)
    author_id = db.Column(db.Integer, nullable=False)
    author_name = db.Column(db.String(20), nullable=False)
    questionResponseID = db.Column(
        db.Integer,
        db.ForeignKey('questionresponse.questionResponseID'),
        nullable=False)
    questionresponse = db.relationship('Questionresponse',
                                       backref='question_response')

    def __repr__(self):
        return f"Optionresponse('{self.optionResponseID}','{self.content}')"

    def get_id(self):
        return '{}'.format(self.optionResponseID)

    def get_content(self):
        return '{}'.format(self.content)

    def get_author_name(self):
        return '{}'.format(self.author_name)

    def get_author_id(self):
        return '{}'.format(self.author_id)

    def get_question_response_id(self):
        return '{}'.format(self.questionResponseID)
예제 #23
0
class ProFeedback(db.Model):

    feedbackID = db.Column(db.Integer, autoincrement=True, primary_key=True)
    surveyName = db.Column(db.String(64), nullable=False)
    dt_time = db.Column(db.DateTime, nullable=False, default=datetime.utcnow)
    content = db.Column(db.String(500), nullable=False)
    userID = db.Column(db.Integer, db.ForeignKey('user.userID'))
    surveyID = db.Column(db.Integer, db.ForeignKey('survey.surveyID'))
    survey = db.relationship('Survey', backref='survey_feedback')

    def __repr__(self):
        return f"Feedback('{self.feedbackID}','{self.surveyName}')"

    def get_id(self):
        return '{}'.format(self.feedbackID)

    def get_survey_name(self):
        return '{}'.format(self.surveyName)

    def get_content(self):
        return '{}'.format(self.content)

    def get_date(self):
        return '{}'.format(self.dt_time)

    def get_user_id(self):
        return '{}'.format(self.userID)

    def get_survey_id(self):
        return '{}'.format(self.surveyID)
예제 #24
0
class People(Common, db.Model):
    """人员模型"""
    __tablename__ = 'people'
    id = db.Column(db.Integer, index=True, primary_key=True)

    name = db.Column(db.String(length=50), nullable=False, comment='人名')
    telephone = db.Column(db.String(length=13), nullable=False, comment='联系方式')
    company_id = db.Column(db.Integer,
                           db.ForeignKey('firm.id'),
                           nullable=False)
    remarks = db.Column(db.String(length=255), default='', comment='人员备注')

    order_form_all = db.relationship('OrderForm',
                                     lazy='select',
                                     backref='person')

    def __init__(self,
                 name: str,
                 telephone: str,
                 company_id: int,
                 remarks: str = None):
        self.name = name
        self.telephone = telephone
        self.company_id = company_id
        self.remarks = remarks
예제 #25
0
파일: model.py 프로젝트: fdenzer/unary
class User(ExportableMixin, db.Model):
    id = db.Column(db.Integer, primary_key=True)
    enabled = db.Column(db.Boolean, default=True, nullable=False)
    username = db.Column(db.String(80), unique=True, nullable=False)
    fullname = db.Column(db.String(80), nullable=False)
    email = db.Column(db.String(80), unique=True, nullable=False)
    color = db.Column(db.String(20), default='black', nullable=False)
    picture = db.Column(db.String(80), default='generic.png')
    balance = db.Column(db.Float, default='0', nullable=False)
    created = db.Column(db.DateTime, default=db.func.now())

    transactions = db.relationship('Transaction',
                                   backref='user',
                                   order_by=lambda: Transaction.date.desc())

    export_blacklist = ['fullname', 'email', 'transactions', 'created']

    @property  # short prefix of full name that allows a broad search (privacy)
    def namePrefix(self):
        return self.fullname[:3]

    @property  # hash email to allow comparisons (privacy)
    def emailDigest(self):
        return sha256(self.email.lower().encode('utf-8')).hexdigest()

    @property
    def lastActivity(self):
        if self.transactions and len(self.transactions) > 0:
            return self.transactions[0].date
        return self.created

    def __repr__(self):
        return '<User {}>'.format(self.username)
예제 #26
0
class Role(db.Model):
    __tablename__ = 'roles'
    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(64), unique=True)
    default = db.Column(db.Boolean, default=False, index=True)
    permissions = db.Column(db.Integer)
    users = db.relationship('User', backref='role', lazy='dynamic')

    @staticmethod
    def insert_roles():
        roles = {
            'User':
            (Permission.FOLLOW | Permission.COMMENT | Permission.POST_ARTICLE,
             True),
            'Moderator':
            (Permission.FOLLOW | Permission.COMMENT | Permission.POST_ARTICLE
             | Permission.MODIFY_COMMENT, False),
            'Admin': (0xff, False)
        }

        for role in roles:
            r = Role.query.filter_by(name=role).first()
            if r is None:
                r = Role()
            # Be able to modify permissions
            r.name = role
            r.default = roles.get(role)[1]
            r.permissions = roles.get(role)[0]
            db.session.add(r)
        db.session.commit()
예제 #27
0
class OrderForm(Common, db.Model):
    """订单模型"""
    __tablename__ = 'order_form'
    id = db.Column(db.Integer, index=True, primary_key=True)

    person_id = db.Column(db.Integer,
                          db.ForeignKey('people.id'),
                          nullable=False,
                          comment='订单目标对象')
    product_id = db.Column(db.Integer,
                           db.ForeignKey('product.id'),
                           nullable=False,
                           comment='产品编号')
    price = db.Column(db.DECIMAL(precision=9, decimal_return_scale=2),
                      default=0.0,
                      comment='订单价格')
    quantity = db.Column(db.DECIMAL(precision=9, decimal_return_scale=2),
                         default=0.0,
                         comment='订单数量')
    order_id = db.Column(db.Integer,
                         db.ForeignKey('order.id'),
                         nullable=False,
                         comment='订单备注编号')
    unit_id = db.Column(db.SMALLINT,
                        db.ForeignKey('product_unit.id'),
                        nullable=False,
                        comment='产品单位ID')
    real_quantity = db.Column(db.DECIMAL(9, 2),
                              nullable=False,
                              comment='实际发货数量')

    unit = db.relationship('ProductUnit', lazy='select')

    def __init__(self,
                 person_id: int,
                 product_id: int,
                 price: float,
                 quantity: float,
                 order_id: int,
                 unit_id: int,
                 real_quantity: float = None):
        self.person_id = person_id
        self.product_id = product_id
        self.price = price
        self.quantity = quantity
        self.order_id = order_id
        self.unit_id = unit_id
        self.real_quantity = self._init_real_quantity(real_quantity)

    def _init_real_quantity(self, quantity):
        """实际数量初始化设定"""
        try:
            quantity = float(quantity)
        except TypeError:
            return self.quantity
        except ValueError:
            return self.quantity
        else:
            return quantity
예제 #28
0
class User(db.Model, UserMixin):
    id = db.Column(db.Integer, primary_key=True)
    password_hash = db.Column(db.String(100), nullable=False)
    login = db.Column(db.String(100), nullable=False, unique=True)
    posts = db.relationship('Posts', cascade="all, delete", backref='user')

    def __repr__(self):
        return f"{self.id}:{self.login}"
예제 #29
0
class Level(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(80), unique=True, nullable=False)
    price = db.Column(db.Integer, nullable=True)
    lessons = db.relationship('Lesson', backref='level')

    def __repr__(self):
        return '<Level %r>' % self.level
예제 #30
0
class Product(Common, db.Model):
    """产品模型"""
    __tablename__ = 'product'
    id = db.Column(db.Integer, index=True, primary_key=True)

    name = db.Column(db.String(length=50), nullable=False, comment='产品名')
    price = db.Column(db.DECIMAL(precision=9, decimal_return_scale=2),
                      default=0.00,
                      nullable=False,
                      comment='产品单价')
    unit_id = db.Column(db.SMALLINT,
                        db.ForeignKey('product_unit.id'),
                        nullable=False,
                        comment='产品单位ID')

    EPS = db.relationship('ExternalPrice',
                          lazy='select',
                          cascade="all, delete-orphan",
                          backref='product')
    all_order = db.relationship('OrderForm',
                                lazy='select',
                                cascade="all, delete-orphan",
                                backref='product')
    unit = db.relationship('ProductUnit', lazy='select')

    def __init__(self, name: str, price: float, unit_id: int = None):
        self.name = name
        self.price = price
        self.unit_id = unit_id

    @property
    def unit_all(self):
        """可用计量单位"""
        return ProductUnit.query.filter(
            or_(ProductUnit.id == self.unit_id,
                ProductUnit.parent_id == self.unit_id)).all()

    def broadcast(self):
        """新建产品完成后,只允许执行一次.将数据更新每家公司的专价
        broadcast:广播
        """
        for company in Firm.query.all():
            ExternalPrice(product_id=self.id,
                          company_id=company.id,
                          price=self.price,
                          unit_id=self.unit_id).direct_commit_()
예제 #31
0
    respond_id = db.Column(db.Integer, db.ForeignKey('user.id'))

    init = db.relationship('User', foreign_keys=[init_id])
    respond = db.relationship('User', foreign_keys=[respond_id])


class Posts(db.Model):
    id = db.Column(db.Integer, primary_key=True, autoincrement=True)
    content = db.Column(db.String(256))
    creator_id = db.Column(db.Integer, db.ForeignKey('user.id'))
    creator_login = db.Column(db.String(50))
    creator = db.relationship('User', backref='posts')
    login = db.Column(db.String(256))
    timestamp = db.Column(db.DateTime, default=datetime.datetime.now)
    photo = db.Column(db.BLOB)
    photo_type = db.Column(db.String(50))

    @property
    def jsonable(self):
        return {
            'post_id': self.id,
            'timestamp': str(self.timestamp),
            'has_photo': self.photo is not None
        }


User.follow = db.relationship('User', secondary='follow', primaryjoin=User.id==Follow.init_id,
                              secondaryjoin=User.id==Follow.respond_id)


db.create_all(app=app)