You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hello,
I hope you can help me.
Im using python 3.9.0, Flask 1.1.2, flask-restplus 0.13.0, Flask_SQLAlchemy2.4.4 and SQLAlchemy 1.3.20.
I have a problem with a nested api model, which looks like this:
lightstate = api.model('LightState', {
'red': fields.Integer(attribute='red', description='red part of the rgb light'),
'green': fields.Integer(attribute='green', description='green part of the rgb light'),
'blue': fields.Integer(attribute='blue', description='blue part of the rgb light'),
'bri': fields.Integer(attribute='bri', description='brightness of the light')
})
lights = api.model('Lights',{
'id': fields.Integer(readOnly=True, description='The database id of the light'),
'name': fields.String(required=True, description='light name'),
'state': fields.Nested(lightstate)
})
db = SQLAlchemy()
class Lights(db.Model):
__bind_key__ = 'lights'
id = db.Column(db.Integer, primary_key=True)
name = db.Column(db.String(255))
red = db.Column(db.Integer)
green = db.Column(db.Integer)
blue = db.Column(db.Integer)
bri = db.Column(db.Integer)
def __init__(self, name, red, green, blue, bri):
self.name = name
self.red = red
self.green = green
self.blue = blue
self.bri = bri
If I send a request, I'm getting this response with null values:
But if I remove the nested field from my api model 'lights' and add all fields, the values are not null.
lights = api.model('Lights', {
'id': fields.Integer(readOnly=True, description='The database id of the light'),
'name': fields.String(required=True, description='light name'),
'red': fields.Integer(description='red part of the rgb light'),
'green': fields.Integer(description='green part of the rgb light'),
'blue': fields.Integer(description='blue part of the rgb light'),
'bri': fields.Integer(description='brightness of the light')
})
Hello,
I hope you can help me.
Im using python 3.9.0, Flask 1.1.2, flask-restplus 0.13.0, Flask_SQLAlchemy2.4.4 and SQLAlchemy 1.3.20.
I have a problem with a nested api model, which looks like this:
This is my my request handler:
And my dto:
If I send a request, I'm getting this response with null values:
But if I remove the nested field from my api model 'lights' and add all fields, the values are not null.
I want to use the nested fields. How do I get the values in my response?
Thanks in advance
The text was updated successfully, but these errors were encountered: