import uuid import datetime from sqlalchemy.orm import relationship from app.db import db from app.utils import default_created_at CommitTagAssociation = db.Table('commit_tag', db.Column('commit_id', db.Text, db.ForeignKey('commits.uuid')), db.Column('tag_id', db.Text, db.ForeignKey('tags.uuid'))) class Commit(db.Model): __tablename__ = 'commits' uuid = db.Column(db.Text, primary_key=True) hash = db.Column(db.Text) tags = relationship('Tag', secondary=CommitTagAssociation) created_at = db.Column(db.DateTime, default=default_created_at) is_archived = db.Column(db.Boolean) def __init__(self, hash): self.uuid = str(uuid.uuid1()) self.hash = hash self.is_archived = False class Tag(db.Model): __tablename__ = 'tags'
def update(self): db.session.commit() def delete(self): db.session.delete(self) db.session.commit() def __repr__(self): return f''' <Author id: {self.id}, name: {self.name}, surname: {self.surname}, email: {self.email}, description: {self.description}, technologies: {self.technologies} projects: {self.projects} >''' author_technology = db.Table( 'author_technology', db.Column('author_id', db.Integer, db.ForeignKey('author.id'), primary_key=True), db.Column('technology_id', db.Integer, db.ForeignKey('technology.id'), primary_key=True))
from sqlalchemy import Column, Integer, ForeignKey from sqlalchemy.ext.declarative import declarative_base from typing import Text from app.db import db Base = declarative_base() articles_keywords = db.Table( 'article_keyword', db.Column('article_id', db.Integer, db.ForeignKey('articles.id', ondelete='CASCADE'), nullable=False), db.Column('keyword_id', db.Integer, db.ForeignKey('keywords.id', ondelete='CASCADE'), nullable=False)) class Article(db.Model): __tablename__ = 'articles' id = db.Column(db.Integer, primary_key=True) title = db.Column(db.String(255), nullable=False) source = db.Column(db.String(255), nullable=False) date = db.Column(db.DateTime, nullable=False) url = db.Column(db.String(255), nullable=False) author = Column(Integer, ForeignKey("authors.id")) sentences_count = db.Column(db.Integer)
from app.db import db, CRUDMixin, TimestampMixin class ClassifiedAd(db.Model, CRUDMixin, TimestampMixin): __tablename__ = 'classified_ad' name = db.Column(db.String(255), nullable=False) description = db.Column(db.Text) publisher = db.Column(db.String(255), nullable=False) phone = db.Column(db.String(80)) email = db.Column(db.String(255)) user_id = db.Column(db.Integer, db.ForeignKey('users.id')) image = db.Column(db.LargeBinary) categories = db.relationship('ClassifiedTags', secondary='ads_tags_rel', lazy='subquery', backref=db.backref('ads', lazy=True)) class ClassifiedTags(db.Model, CRUDMixin): __tablename__ = 'classified_tags' name = db.Column(db.String(255), nullable=False) adds_tags_rel = db.Table( 'ads_tags_rel', db.Model.metadata, db.Column('ad_id', db.Integer, db.ForeignKey('classified_ad.id')), db.Column('tag_id', db.Integer, db.ForeignKey('classified_tags.id')))
from app.db import db from datetime import datetime from flask import session from requests import get tipos_de_centro = db.Table('centro_tiene_tipo', db.Column('centro_id', db.Integer, db.ForeignKey( 'centro_de_ayuda.id'), primary_key=True), db.Column('tipo_de_centro_id', db.Integer, db.ForeignKey( 'tipo_de_centro.id'), primary_key=True) ) class Centro_de_ayuda(db.Model): __tablename__ = 'centro_de_ayuda' id = db.Column(db.Integer, primary_key=True) nombre = db.Column(db.String) telefono = db.Column(db.String) email = db.Column(db.String) sitio_web = db.Column(db.String) hora_de_apertura = db.Column(db.Time) hora_de_cierre = db.Column(db.Time) direccion = db.Column(db.String) protocolo_de_vista = db.Column(db.String) coordenada_x = db.Column(db.Integer) coordenada_y = db.Column(db.Integer) publicado = db.Column(db.Boolean) historico = db.Column(db.Integer) tipos_de_centro = db.relationship('Tipo_de_centro', secondary=tipos_de_centro, backref=db.backref( 'centros_de_ayuda_de_este_tipo', lazy=True), lazy='subquery')
sms = db.Column(db.SmallInteger, nullable=False, default=-1) data = db.Column(db.SmallInteger, nullable=False, default=-1) # 融合产品可以捆绑的固话数量 fix_line_num = db.Column(db.SmallInteger, nullable=False, default=0) # 融合产品可以捆绑的宽带数量 broad_band_num = db.Column(db.SmallInteger, nullable=False, default=0) # 融合产品和以捆绑的手机数量 mobile_num = db.Column(db.SmallInteger, nullable=False, default=0) #discount = db.Column(db.Float, nullable=False, default=1.0) # 前两个字母表示类型,后六个字母表示存费或者合约的费用等 pre_fee = db.Column(db.String(8), nullable=False, default='00000000') # 渠道关联 channel_relation = db.Table( 'channel_relation', db.Column('sub_chnl_no', db.String(12), db.ForeignKey('channels.chnl_no')), db.Column('sup_chnl_no', db.String(12), db.ForeignKey('channels.chnl_no'))) # 渠道 class Channel(db.Model): __tablename__ = "channels" chnl_no = db.Column(db.String(12), primary_key=True) chnl_name = db.Column(db.String(200), nullable=False) chnl_cat_1 = db.Column(db.SmallInteger, nullable=False) chnl_cat_2 = db.Column(db.SmallInteger, nullable=False) chnl_cat_3 = db.Column(db.SmallInteger, nullable=False) # 经纬度,默认 -1,表示非线下渠道 longitude = db.Column(db.String(20), nullable=False, default='-1') latitude = db.Column(db.String(20), nullable=False, default='-1') contract_life = db.Column(db.Date, nullable=False)
from app.db import db permission_user_table = db.Table('permission_user', db.Model.metadata, db.Column( 'permission_id', db.Integer, db.ForeignKey('permissions.id') ), db.Column( 'user_id', db.Integer, db.ForeignKey('users.id') ) ) permission_role_table = db.Table('permission_role', db.Model.metadata, db.Column( 'permission_id', db.Integer, db.ForeignKey('permissions.id') ), db.Column( 'role_id', db.Integer, db.ForeignKey('roles.id') ) ) category_product_table = db.Table('category_product', db.Model.metadata, db.Column( 'category_id',
from app.db import db from datetime import datetime from sqlalchemy import update from flask import session from app.models.rol import Rol # Siguiendo las diapo de la clase y este video https://www.youtube.com/watch?v=OvhoYbjtiKc # Hay un trucazo para generar la BD en el minuto 11:37 roles = db.Table('usuario_tiene_rol', db.Column('usuario_id', db.Integer, db.ForeignKey( 'usuario.id')), db.Column('rol_id', db.Integer, db.ForeignKey( 'rol.id')) ) class User(db.Model): __tablename__ = 'usuario' id = db.Column(db.Integer, primary_key=True) usuario = db.Column(db.String) clave = db.Column(db.String) nombre = db.Column(db.String) apellido = db.Column(db.String) email = db.Column(db.String) activo = db.Column(db.Integer) fecha_actualizacion = db.Column(db.String) fecha_creacion = db.Column(db.String) historico = db.Column(db.Integer) # Voy a crear una relacion entre tablas # Lleva como argumento las clases involucradas
from app.db import db from app.models.permiso import Permiso permisos = db.Table( 'rol_tiene_permiso', db.Column('rol_id', db.Integer, db.ForeignKey('rol.id'), primary_key=True), db.Column('permiso_id', db.Integer, db.ForeignKey('permiso.id'), primary_key=True)) class Rol(db.Model): __tablename__ = 'rol' id = db.Column(db.Integer, primary_key=True) nombre = db.Column(db.String) permisos = db.relationship('Permiso', secondary=permisos, backref=db.backref('roles_con_el_permiso', lazy=True), lazy='subquery') def get_by_nombre(nombre_rol): return Rol.query.filter_by(nombre=nombre_rol).first() def all(): return Rol.query.all()
def update(self): db.session.commit() def delete(self): db.session.delete(self) db.session.commit() def __repr__(self): return f''' <Project id: {self.id}, name: {self.name}, description: {self.description}, repository_url: {self.repository_url}, author_id: {self.author_id}, technologies: {self.technologies} >''' project_technology = db.Table( 'project_technology', db.Column('project_id', db.Integer, db.ForeignKey('project.id'), primary_key=True), db.Column('technology_id', db.Integer, db.ForeignKey('technology.id'), primary_key=True))
self.major_version, self.minor_version, ) def fullname(self): return '{0} {1}.{2}'.format( self.name, self.major_version, self.minor_version, ) # Define security models roles_users = db.Table( 'roles_users', db.Column('user_id', db.Integer(), db.ForeignKey('user.id')), db.Column('role_id', db.Integer(), db.ForeignKey('role.id')) ) class Role(db.Model, RoleMixin): id = db.Column(db.Integer(), primary_key=True) name = db.Column(db.String(80), unique=True) description = db.Column(db.String(255)) def __str__(self): return self.name class User(db.Model, UserMixin): id = db.Column(db.Integer, primary_key=True)
from datetime import datetime import requests from app.db import db, BaseModelMixin albums_artists = db.Table( 'albums_artists', db.Model.metadata, db.Column('albums_artists_id', db.Integer, primary_key=True), db.Column('artist_id', db.Integer, db.ForeignKey('artists.artist_id', ondelete='CASCADE'), nullable=False), db.Column('album_id', db.Integer, db.ForeignKey('albums.album_id', ondelete='CASCADE'), nullable=False) ) playlists_songs = db.Table( 'playlists_songs', db.Model.metadata, db.Column('playlists_songs_id', db.Integer, primary_key=True), db.Column('playlist_id', db.Integer, db.ForeignKey('playlists.playlist_id', ondelete='CASCADE'), nullable=False), db.Column('song_id', db.Integer, db.ForeignKey('songs.song_id', ondelete='CASCADE'), nullable=False) ) played_songs = db.Table( 'played_songs', db.Column('played_song_id', db.Integer, primary_key=True), db.Column('song_id', db.Integer, db.ForeignKey('songs.song_id', ondelete='CASCADE',), nullable=False), db.Column('user_id', db.Integer, db.ForeignKey('users.user_id', ondelete='CASCADE',), nullable=False), db.Column('created_at', db.DateTime, default=datetime.utcnow), db.Column('updated_at', db.DateTime, default=datetime.utcnow, onupdate=datetime.utcnow), db.Column('active', db.Integer, default=1) )