8000 Merge pull request #1452 from jorwoods/jorwoods/django_filters_details · mattholy/server-client-python@23f33e3 · GitHub
[go: up one dir, main page]

Skip to content
8000

Commit 23f33e3

Browse files
authored
Merge pull request tableau#1452 from jorwoods/jorwoods/django_filters_details
docs: clarify django style filters
2 parents b6cde48 + 3ae9fdf commit 23f33e3

File tree

1 file changed

+45
-4
lines changed

1 file changed

+45
-4
lines changed

docs/filter-sort.md

Lines changed: 45 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,36 @@ Sort can take multiple args, with desc direction added as a (-) prefix
138138
workbooks = workbooks.order_by("project_name", "-created_at")
139139
```
140140

141+
### Indexing and slicing
142+
143+
Querysets can be indexed and sliced like a list. The query is executed at when
144+
the queryset is indexed or sliced.
145+
```py
146+
# Get the first item in the queryset
147+
flow = server.flows.filter(owner_name="admin")[0]
148+
149+
# Get the last item in the queryset
150+
flow = server.flows.filter(owner_name="admin")[-1]
151+
152+
# Get the most recent 10 runs from a flow
153+
runs = server.flow_runs.filter(flow_id=flow.id, page_size=10).order_by("-created_at")[:10]
154+
```
155+
156+
### Supported endpoints
157+
158+
The following endpoints support the Django style filters and sorts:
159+
160+
* Datasources
161+
* Flow Runs
162+
* Flows
163+
* Groups
164+
* Groupsets
165+
* Jobs
166+
* Projects
167+
* Users
168+
* Views
169+
* Workbooks
170+
141171
### More detailed examples
142172

143173
```py
@@ -147,13 +177,19 @@ workbooks = server.workbooks.all()
147177
# filters can be appended in new lines
148178
workbooks = workbooks.filter(project_name=project_name)
149179

180+
# multiple filters can be added in a single line
181+
workbooks = workbooks.filter(project_name=project_name, owner_name=owner_name, size__gte=1000)
182+
183+
# Multiple filters can be added through chaining.
184+
workbooks = workbooks.filter(project_name=project_name).filter(owner_name=owner_name).filter(size__gte=1000)
185+
186+
# Find all views in a project, with a specific tag
187+
views = server.views.filter(project_name=project_name, tags="stale")
188+
150189
# sort can take multiple args, with desc direction added as a (-) prefix
151190
workbooks = workbooks.order_by("project_name", "-created_at")
152191

153-
# pagination take these two keywords
154-
workbooks = workbooks.paginate(page_size=10, page_number=2)
155-
156-
# query is executed at time of access
192+
# query is executed at time of iteration
157193
for workbook in workbooks:
158194
print(workbook)
159195

@@ -165,6 +201,11 @@ all_workbooks = server.workbooks.filter(project_name=project_name).order_by("-pr
165201

166202
# operators are implemented using dunderscore
167203
all_workbooks = server.workbooks.filter(project_name__in=["Project A", "Project B"])
204+
205+
# How many items are in the queryset?
206+
flows = server.flows.filter(owner_name="admin")
207+
print(len(flows))
208+
168209
```
169210

170211
### Operators available

0 commit comments

Comments
 (0)
0