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

Add ModelView.form_query property to create form-filtering feature #733

Closed
1 task done
lukeclimen opened this issue Mar 20, 2024 · 2 comments · Fixed by #745 or #777
Closed
1 task done

Add ModelView.form_query property to create form-filtering feature #733

lukeclimen opened this issue Mar 20, 2024 · 2 comments · Fixed by #745 or #777

Comments

@lukeclimen
Copy link
Contributor

Checklist

  • There are no similar issues or pull requests for this yet.

Is your feature related to a problem? Please describe.

In the list view for a model with relationships, I am able to override the ModelView.list_query property to customize the select query. This allows me to add filters to show results that are relevant. This functionality doesn't exist for the form view of a model.

Describe the solution you would like.

Adding an extendable ModelView.form_query would add another tool to solve the problems laid out in the documentation for relationship loading. Assuming that it's possible, the default function can remain the same as the existing query to populate a form, with users able to override that property in their own models if they need to.

Describe alternatives you considered

There is ModelView.form_ajax_refs, which allows a more restricted experience to ModelView.list_query. Where this breaks down for me is if I need to filter the select statement based on a property that isn't directly on the class described in the class. ModelView.form_ajax_refs allows me to specify fields on the given relationship. In the docs, the example is the street and zip_code fields on the address relationship. To extend the example, if the street property pointed to an object, and I wanted to filter this relationship based on a property of the street class, I would not be able to do so.

Additional context

There was a related issue that was raised in the past (now closed), where the user had created their own custom query within the update_model call. I think that the use case in this issue would have benefitted from a ModelView.form_query function to override as a more simplified solution.

There have also been two recent posts (here and here) in the Q&A discussion area about wanting to filter relationships in the form view.

@lukeclimen
Copy link
Contributor Author

@aminalaee if you are able to confirm that the proposed changes would be possible in the form view, I can create a PR to address this.

@aminalaee
Copy link
Owner

I think this makes sense, can you please proceed with a basic implementation and tests to see how it looks and we work on it?

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