consulta de id y nombres de 2 tablas distintas
Publicado por susana lopez (1 intervención) el 14/11/2022 05:38:24
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#se supone debe de devolver id : 7 name: un nombre
#consulta alas tablas
from flask import jsonify
from ..schemas import schemaNotices, schemaAuthor,schemaCategory
from .lPrensa import listaPrensa
from ..models import db, Notices, Author, Category
base = db.session
class Avisoss:
def listAvisos(self):
Av = base.query(Notices, Author, Category).filter(Notices.id_category == Category.id).filter
(Notices.id_Author == Author.id).filter(Notices = True).all()
Avs =[]
for item in Av:
Avs.append(schemaNotices(item[0]), schemaCategory(item[1]),schemaAuthor(item[2]))
try:
return jsonify({"data": Avs}), 200
except Exception as error:
return jsonify({"error":str(error)}), 500
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#schema
from dataclasses import fields
from flask_marshmallow import Marshmallow
from flask import jsonify
ma = Marshmallow()
#TODO : Declaracion de Schema
class Schema_Prensa(ma.Schema):
class Meta:
fields = ('id_category',' name_category','id_author','id_name_autor')
#TODO: Istancia de los distintos Schemas
schemaPs = Schema_Prensa()
schemaPss = Schema_Prensa(many=True)
Valora esta pregunta


-1