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
I have JSON in following format (lets call it Object):
{ name: somename,
attributes:[{tag:tag1,value:value1}...]
...}
What I want to do is represent attributes as a class Attributes, so I can add method which will find value from passed tag. What I did is something like this:
class Attribute(BaseModel):
tag:str
value:str
class Attributes(BaseModel):
attributes:list[Attribute]
def get_attribute_val(tag):
.......
class Object(BaseModel):
name:str
attributes:Attributes #My error
With this I always get model_type error for attributes in Object class. When I pass attributes:[{tag:tag1,value:value1}...] to only Attributes class everything works as I want.
Do you have some suggestion how to solve this. Thanks.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Hello all,
I have JSON in following format (lets call it Object):
{ name: somename,
attributes:[{tag:tag1,value:value1}...]
...}
What I want to do is represent attributes as a class Attributes, so I can add method which will find value from passed tag. What I did is something like this:
With this I always get model_type error for attributes in Object class. When I pass
attributes:[{tag:tag1,value:value1}...]
to only Attributes class everything works as I want.Do you have some suggestion how to solve this. Thanks.
Beta Was this translation helpful? Give feedback.
All reactions