From 8410b677dbcf34fb15d608d026da28e83a73ef4f Mon Sep 17 00:00:00 2001 From: Jordan Woods <13803242+jorwoods@users.noreply.github.com> Date: Thu, 29 Aug 2024 20:57:30 -0500 Subject: [PATCH 1/3] docs: clarify django style filters Add notes about supported endpoints and being able to use multiple filters at a time. --- docs/filter-sort.md | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/docs/filter-sort.md b/docs/filter-sort.md index 1d8a947ac..8da06eef7 100644 --- a/docs/filter-sort.md +++ b/docs/filter-sort.md @@ -138,6 +138,21 @@ Sort can take multiple args, with desc direction added as a (-) prefix workbooks = workbooks.order_by("project_name", "-created_at") ``` +### Supported endpoints + +The following endpoints support the Django style filters and sorts: + +* Datasources +* Flow Runs +* Flows +* Groups +* Groupsets +* Jobs +* Projects +* Users +* Views +* Workbooks + ### More detailed examples ```py @@ -147,6 +162,12 @@ workbooks = server.workbooks.all() # filters can be appended in new lines workbooks = workbooks.filter(project_name=project_name) +# multiple filters can be added in a single line +workbooks = workbooks.filter(project_name=project_name, owner_name=owner_name, size__gte=1000) + +# Find all views in a project, with a specific tag +views = server.views.filter(project_name=project_name, tags="stale") + # sort can take multiple args, with desc direction added as a (-) prefix workbooks = workbooks.order_by("project_name", "-created_at") From bd1b86c9de3b30162501899cf9428623be2d33d6 Mon Sep 17 00:00:00 2001 From: Jordan Woods <13803242+jorwoods@users.noreply.github.com> Date: Sun, 1 Sep 2024 12:38:33 -0500 Subject: [PATCH 2/3] docs: chaining filters --- docs/filter-sort.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/docs/filter-sort.md b/docs/filter-sort.md index 8da06eef7..ddd2cbbee 100644 --- a/docs/filter-sort.md +++ b/docs/filter-sort.md @@ -165,6 +165,9 @@ workbooks = workbooks.filter(project_name=project_name) # multiple filters can be added in a single line workbooks = workbooks.filter(project_name=project_name, owner_name=owner_name, size__gte=1000) +# Multiple filters can be added through chaining. +workbooks = workbooks.filter(project_name=project_name).filter(owner_name=owner_name).filter(size__gte=1000) + # Find all views in a project, with a specific tag views = server.views.filter(project_name=project_name, tags="stale") From 3ae9fdf0988536fbe36d4c23b35ba5ff515efab4 Mon Sep 17 00:00:00 2001 From: Jordan Woods <13803242+jorwoods@users.noreply.github.com> Date: Mon, 2 Sep 2024 06:59:39 -0500 Subject: [PATCH 3/3] docs: detail indexing, slicing, and length checking --- docs/filter-sort.md | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/docs/filter-sort.md b/docs/filter-sort.md index ddd2cbbee..feaf12102 100644 --- a/docs/filter-sort.md +++ b/docs/filter-sort.md @@ -138,6 +138,21 @@ Sort can take multiple args, with desc direction added as a (-) prefix workbooks = workbooks.order_by("project_name", "-created_at") ``` +### Indexing and slicing + +Querysets can be indexed and sliced like a list. The query is executed at when +the queryset is indexed or sliced. +```py +# Get the first item in the queryset +flow = server.flows.filter(owner_name="admin")[0] + +# Get the last item in the queryset +flow = server.flows.filter(owner_name="admin")[-1] + +# Get the most recent 10 runs from a flow +runs = server.flow_runs.filter(flow_id=flow.id, page_size=10).order_by("-created_at")[:10] +``` + ### Supported endpoints The following endpoints support the Django style filters and sorts: @@ -174,10 +189,7 @@ views = server.views.filter(project_name=project_name, tags="stale") # sort can take multiple args, with desc direction added as a (-) prefix workbooks = workbooks.order_by("project_name", "-created_at") -# pagination take these two keywords -workbooks = workbooks.paginate(page_size=10, page_number=2) - -# query is executed at time of access +# query is executed at time of iteration for workbook in workbooks: print(workbook) @@ -189,6 +201,11 @@ all_workbooks = server.workbooks.filter(project_name=project_name).order_by("-pr # operators are implemented using dunderscore all_workbooks = server.workbooks.filter(project_name__in=["Project A", "Project B"]) + +# How many items are in the queryset? +flows = server.flows.filter(owner_name="admin") +print(len(flows)) + ``` ### Operators available