Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Nested models #86

Open
wpeterw opened this issue Dec 11, 2023 · 5 comments · May be fixed by #140
Open

Nested models #86

wpeterw opened this issue Dec 11, 2023 · 5 comments · May be fixed by #140
Milestone

Comments

@wpeterw
Copy link

wpeterw commented Dec 11, 2023

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

@samuelcolvin
Copy link
Member

You mean in a table?

I think that's not yet supported.

@wpeterw
Copy link
Author

wpeterw commented Dec 11, 2023

yes, in a table, my data has nested objects.

@Dejiah
Copy link
Contributor

Dejiah commented Dec 11, 2023

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

@hillstub
Copy link

hillstub commented Feb 3, 2024

One work-around could be to create a custom TeamRow model with non-nested fields that you want to display.

@MMartin09
Copy link

@hillstub Could you maybe provide a sample code? I am currently facing the same problem.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants