@@ -138,6 +138,36 @@ 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
+
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
+
141
171
### More detailed examples
142
172
143
173
``` py
@@ -147,13 +177,19 @@ workbooks = server.workbooks.all()
147
177
# filters can be appended in new lines
148
178
workbooks = workbooks.filter(project_name = project_name)
149
179
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
+
150
189
# sort can take multiple args, with desc direction added as a (-) prefix
151
190
workbooks = workbooks.order_by(" project_name" , " -created_at" )
152
191
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
157
193
for workbook in workbooks:
158
194
print (workbook)
159
195
@@ -165,6 +201,11 @@ all_workbooks = server.workbooks.filter(project_name=project_name).order_by("-pr
165
201
166
202
# operators are implemented using dunderscore
167
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
+
168
209
```
169
210
170
211
### Operators available
0 commit comments