DEV Community

amanjn98
amanjn98

Posted on

how to create nested json by mapping values to class in pyhton (querying postgres)

from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy import Column, Integer, String, Float
Base = declarative_base()

class Report(Base):
    __tablename__ = 'report'

    id = Column(Integer, primary_key=True)
    a=Column('a',String)
    b=Column('b',Integer)
    c= Column('c', Integer)
    data=ChildClass(b,c)

    def __init__(self, o,new_data):
        self.a = o
        self.data=new_data;

class ChildClass(object):

    def __init__(self,bdata,cdata):
       self.b=bdata
       self.c=cdata

Api :
@app.route('/getdata', methods=['GET'])
def get_operator():
    try:
        engine

Top comments (0)