@@ -138,6 +138,21 @@ Sort can take multiple args, with desc direction added as a (-) prefix
138
138
workbooks = workbooks.order_by(" project_name" , " -created_at" )
139
139
```
140
140
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
+
141
156
### Supported endpoints
142
157
143
158
The following endpoints support the Django style filters and sorts:
@@ -174,10 +189,7 @@ views = server.views.filter(project_name=project_name, tags="stale")
174
189
# sort can take multiple args, with desc direction added as a (-) prefix
175
190
workbooks = workbooks.order_by(" project_name" , " -created_at" )
176
191
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
181
193
for workbook in workbooks:
182
194
print (workbook)
183
195
@@ -189,6 +201,11 @@ all_workbooks = server.workbooks.filter(project_name=project_name).order_by("-pr
189
201
190
202
# operators are implemented using dunderscore
191
203
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
+
192
209
```
193
210
194
211
### Operators available
0 commit comments