Search on a relationship column #568
johanboekhoven
started this conversation in
General
Replies: 1 comment 1 reply
-
So are you searching in the Task page? Or the relationship page? |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I've subclassed ModelView and I'm overwrting def search_query(self, stmt: Select, term: str) -> Select:
This all works wonderfully well on normal fields, but now I would like to add a custom term that will look into the relationships.
Say I have a task relationship with the status set to finished, I'd like to know if I can make a statement that would work for this situation.
I tried many things, but can't get something to work. I know the statement sqlalchemy statement is wrapped in in the main search statement, so maybe this is not possible at all? My sqlalchemy skills are failing me.
I need something along the lines of this pseudo code:
func.count(select(models.Task).where(models.Task.task_status == task_status.FINISHED))==2
So I want to find out if the relationship Task items have their status set to finished and that there are 2 items that have done so.
Thanks for any info!
Beta Was this translation helpful? Give feedback.
All reactions