-
Notifications
You must be signed in to change notification settings - Fork 176
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
Support one-to-many relationships with ModelView.column_type_formatters #347
Comments
went ahead and opened PR #348 |
Hey, But just an idea, does it make sense to use column_formatter instead of column_type_formatters? |
For this example I think column_formatter would have been simpler. I think it might still be nice to have this type formatter as well for a few reasons.
|
Yes that's right. |
Checklist
Is your feature related to a problem? Please describe.
I often want to display the list of related models for one-to-many relationship so that they can easily be navigated to via the links. The default formatting of printing all model attributes is often unreadable, and is sometimes unusable for larger models.
This is easily solved for one-to-one relationships or the "one-side" of a one-to-many relationship by updating the views
column_type_formatters
with a format function which returns a readable representation. This does not work for the "many-side" of a one-many relationship becauseModelView._default_formatter
only checks the "outer type", which returnslist
. I would expect the formatter to also check the "inner type", which in the below example would beHero
for Team.heros.Describe the solution you would like.
I would like to see an implementation like the the below for
ModelView._default_formatter
. I believe this to be a robust solution as the existing behavior is maintained, even if a formatter for typelist
is registered with the model. If someone specifies a formatter forT
on a model which specifies avalues: List[T] = Relationship(back_populates="something")
field, I think it is safe to assume they expect that formatter to work for that field. It also works for an empty list.Describe alternatives you considered
A potential workaround which requires no changes is to specify a formatter for type
list
, and use a bunch of checks within the function like the below. This doesn't feel like a clean solution to me though.Additional context
The text was updated successfully, but these errors were encountered: