Пример #1
0
class CategoriaModel(base_de_datos.Model):
    __tablename__ = "categorias"
    id = base_de_datos.Column("id", base_de_datos.Integer, primary_key=True)
    nombre = base_de_datos.Column("nombre",
                                  base_de_datos.String(255),
                                  nullable=False)
    creado_el = base_de_datos.Column("creado_el", base_de_datos.DateTime)
    actualizado_el = base_de_datos.Column("actualizado_el",
                                          base_de_datos.DateTime)
    estado = base_de_datos.Column(base_de_datos.Boolean, default=True)

    def __init__(self, nombre):
        self.nombre = nombre

    def guardar_bd(self):
        base_de_datos.session.add(self)
        base_de_datos.session.commit()

    def mostrar_json(self):
        return {'id': self.id, 'nombre': self.nombre, 'estado': self.estado}

    def __str__(self):
        return '%s, %s' % (self.id, self.nombre)
Пример #2
0
class PedidoModel(base_de_datos.Model):
    __tablename__ = "pedidos"
    id = base_de_datos.Column("id", base_de_datos.Integer, primary_key=True)
    id_usuario = base_de_datos.Column(base_de_datos.Integer,
                                      base_de_datos.ForeignKey('usuarios.id'),
                                      nullable=False)
    precio_total = base_de_datos.Column("precio_total", base_de_datos.Numeric)
    estado_pedido = base_de_datos.Column("estado_pedido",
                                         base_de_datos.String(50))
    creado_el = base_de_datos.Column("creado_el", base_de_datos.Datetime)
    actualizado_el = base_de_datos.Column("actualizado_el",
                                          base_de_datos.Datetime)
    estado = base_de_datos.Column(base_de_datos.Boolean, default=True)

    def __init__(self, estado):
        self.estado = estado
Пример #3
0
class ReclamoModel(base_de_datos.Model):
    __tablename__ = "reclamos"
    id = base_de_datos.Column("id", base_de_datos.Integer, primary_key=True)
    id_cliente = base_de_datos.Column("id",
                                      base_de_datos.Integer,
                                      base_de_datos.ForeignKey('usuarios.id'),
                                      nullable=False)
    id_producto = base_de_datos.Column(
        "id",
        base_de_datos.Integer,
        base_de_datos.ForeignKey('productos.id'),
        nullable=False)
    mensaje = base_de_datos.Column("id",
                                   base_de_datos.String(255),
                                   nullable=False)
    fechadecreacion = base_de_datos.Column("id",
                                           base_de_datos.Date,
                                           nullable=False)
    fechadeactualizacion = base_de_datos.Column("id",
                                                base_de_datos.Date,
                                                nullable=False)

    def __init__(self, id_cliente, id_producto, mensaje, fechadecreacion,
                 fechadeactualizacion):
        self.id_cliente = id_cliente
        self.id_producto = id_producto
        self.mensaje = mensaje
        self.fechadecreacion = fechadecreacion
        self.fechadeactualizacion = fechadeactualizacion

    def guardarDB(self):
        base_de_datos.session.add(self)
        base_de_datos.session.commit()

    def mostrar_como_json(self):
        return {
            "id": self.id,
            "id_cliente": self.id_cliente,
            "id_producto": self.id_producto,
            "mensaje": self.mensaje
        }
Пример #4
0
class UsuarioModel(base_de_datos.Model):
    __tablename__ = "Usuarios"
    id = base_de_datos.Column("id", base_de_datos.Integer, primary_key=True)
    nombre = base_de_datos.Column("nombre",
                                  base_de_datos.String(225),
                                  nullable=False)
    apellido_paterno = base_de_datos.Column("apellido_paterno",
                                            base_de_datos.String(225),
                                            nullable=False)
    apellido_materno = base_de_datos.Column("apellido_materno",
                                            base_de_datos.String(225),
                                            nullable=False)
    # fechadenacimiento = base_de_datos.Column("fechadenacimiento",base_de_datos.Date,nullable=False)
    correo = base_de_datos.Column("correo",
                                  base_de_datos.String(225),
                                  nullable=False)
    contrasena = base_de_datos.Column("contrasena",
                                      base_de_datos.String(225),
                                      nullable=False)
    telefono = base_de_datos.Column("telefono",
                                    base_de_datos.Integer,
                                    nullable=False)
    descripcion = base_de_datos.Column("descripcion",
                                       base_de_datos.Text,
                                       nullable=False)
    sexo = base_de_datos.Column("sexo",
                                base_de_datos.String(50),
                                nullable=False)
    # avatar = base_de_datos.Column("avatar",base_de_datos.String(225), default="https://encrypted-tbn0.gstatic.com/images?q=tbn%3AANd9GcSymjxHoVB2hlH41ioYDjkzOd7oVPhJu-uIeQ&usqp=CAU",nullable=False)
    direccion = base_de_datos.Column("direccion",
                                     base_de_datos.String(225),
                                     nullable=False)
    creado_el = base_de_datos.Column(
        "creado_el",
        base_de_datos.DateTime,
        nullable=False,
        default=base_de_datos.func.current_timestamp())
    actualizado_el = base_de_datos.Column("actualizado_el",
                                          base_de_datos.DateTime,
                                          nullable=False)
    estado = base_de_datos.Column(base_de_datos.Boolean, default=True)

    def __init__(self, nombre, apellido_paterno, apellido_materno, correo,
                 contrasena, telefono, descripcion, sexo, direccion):
        self.nombre = nombre
        self.apellido_paterno = apellido_paterno
        self.apellido_materno = apellido_materno
        # self.fechadenacimiento = fechadenacimiento
        self.correo = correo
        self.contrasena = contrasena
        self.telefono = telefono
        self.descripcion = descripcion
        self.sexo = sexo
        # self.avatar = avatar
        self.direccion = direccion
        #self.creado_el = creado_el
        #self.actualizado_el = actualizado_el
        #self.estado = estado

    def guardar_en_la_basededatos(self):
        base_de_datos.session.add(self)
        base_de_datos.session.commit()

    def mostrar_como_json(self):
        return {
            "id": self.id,
            "nombre": self.nombre,
            "apellido_paterno": self.apellido_paterno,
            "apellido_materno": self.apellido_materno,
            "correo": self.correo,
            "contrasena": self.contrasena,
            "telefono": self.telefono,
            "descripcion": self.descripcion,
            "sexo": self.sexo,
            # "avatar": self.avatar,
            "direccion": self.direccion
        }
Пример #5
0
class ProductoModel(base_de_datos.Model):
    __tablename__ = "productos"
    id = base_de_datos.Column("id", base_de_datos.Integer, primary_key=True)
    id_categoria = base_de_datos.Column(
        base_de_datos.Integer,
        base_de_datos.ForeignKey('categorias.id'),
        nullable=False)
    id_usuario = base_de_datos.Column(base_de_datos.Integer,
                                      base_de_datos.ForeignKey('usuarios.id'),
                                      nullable=False)
    imagen = base_de_datos.Column("imagen",
                                  base_de_datos.String(255),
                                  nullable=False)
    nombre = base_de_datos.Column("nombre",
                                  base_de_datos.String(255),
                                  nullable=False)
    descripcion = base_de_datos.Column("descripcion",
                                       base_de_datos.Text,
                                       nullable=False)
    stock = base_de_datos.Column("stock",
                                 base_de_datos.Integer,
                                 nullable=False)
    precio = base_de_datos.Column("precio", base_de_datos.Numeric)
    precio_oferta = base_de_datos.Column("precio_oferta",
                                         base_de_datos.Numeric)
    creado_el = base_de_datos.Column(
        "creado_el",
        base_de_datos.DateTime,
        default=base_de_datos.func.current_timestamp())
    actualizado_el = base_de_datos.Column("actualizado_el",
                                          base_de_datos.DateTime)
    estado = base_de_datos.Column(base_de_datos.Boolean, default=True)

    def __init__(self, id_categoria, id_usuario, imagen, nombre, descripcion,
                 stock, precio, precio_oferta):
        self.id_categoria = id_categoria
        self.id_usuario = id_usuario
        self.imagen = imagen
        self.nombre = nombre
        self.descripcion = descripcion
        self.stock = stock
        self.precio = precio
        self.precio_oferta = precio_oferta

    def guardar_bd(self):
        base_de_datos.session.add(self)
        base_de_datos.session.commit()

    def mostrar_json(self):
        return {
            'id': self.id,
            'id_categoria': self.id_categoria,
            'id_usuario': self.id_usuario,
            'imagen': self.imagen,
            'nombre': self.nombre,
            'descripcion': self.descripcion,
            'stock': self.stock,
            'precio': float(self.precio),
            'precio_oferta': float(self.precio_oferta),
            'estado': self.estado,
        }