8000 docs: detail indexing, slicing, and length checking · tableau/server-client-python@3ae9fdf · GitHub
[go: up one dir, main page]

Skip to content

Commit 3ae9fdf

Browse files
committed
docs: detail indexing, slicing, and length checking
1 parent bd1b86c commit 3ae9fdf

File tree

1 file changed

+21
-4
lines changed

1 file changed

+21
-4
lines changed

docs/filter-sort.md

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,21 @@ 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+
141156
### Supported endpoints
142157

143158
The following endpoints support the Django style filters and sorts:
@@ -174,10 +189,7 @@ views = server.views.filter(project_name=project_name, tags="stale")
174189
# sort can take multiple args, with desc direction added as a (-) prefix
175190
workbooks = workbooks.order_by("project_name", "-created_at")
176191

177-
# pagination take these two keywords
178-
workbooks = workbooks.paginate(page_size=10, page_number=2)
179-
180-
# query is executed at time of access
192+
# query is executed at time of iteration
181193
for workbook in workbooks:
182194
print(workbook)
183195

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

190202
# operators are implemented using dunderscore
191203
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+
192209
```
193210

194211
### Operators available

0 commit comments

Comments
 (0)
0