FastUI
FastUI copied to clipboard
Nested models
I have a model like this (code below), how do I access for instance the name in TeamModel ?
This does not work:
columns=[
DisplayLookup(field="position"),
DisplayLookup(field="team.name"),
class TeamModel(BaseModel):
id: int
name: str
shortName: str
tla: str
crest: str
class Standing(BaseModel):
position: Optional[int] = None
team: Dict[str, str|int]
playedGames: Optional[int] = None
form: Any
won: Optional[int] = None
draw: Optional[int] = None
lost: Optional[int] = None
points: Optional[int] = None
You mean in a table?
I think that's not yet supported.
yes, in a table, my data has nested objects.
I think we could support that by using something like lodash.get
(https://lodash.com/docs/4.17.15#get) in the frontend.
This way the backend can define any nested path to the data in the backend (e.g. teams.name
or even array indexing like teams[0].names[1]
) and the frontend tries to get the given path from the object.
Not sure if performance might be an issue here as we would do this for every cell. Though, I would assume that lodash
's implementation is already quite optimized.
Would be happy to contribute a PR for this if you agree
One work-around could be to create a custom TeamRow model with non-nested fields that you want to display.
@hillstub Could you maybe provide a sample code? I am currently facing the same problem.