You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/api_controller/model_controller/02_model_configuration.md
+58Lines changed: 58 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -206,6 +206,64 @@ class EventModelController(ModelControllerBase):
206
206
!!! info "Learn More About FilterSchema"
207
207
For comprehensive documentation on FilterSchema features, custom expressions, combining filters, and advanced filtering techniques, visit: [https://django-ninja.dev/guides/input/filtering/](https://django-ninja.dev/guides/input/filtering/)
208
208
209
+
### **Disabling Pagination**
210
+
211
+
By default, Model Controllers apply pagination to the list endpoint. If you want to return all results without pagination, you can disable it by setting `pagination` to `None`:
212
+
213
+
```python
214
+
@api_controller("/events")
215
+
classEventModelController(ModelControllerBase):
216
+
model_config = ModelConfig(
217
+
model=Event,
218
+
pagination=None, # Disables pagination
219
+
)
220
+
```
221
+
222
+
When pagination is disabled, the list endpoint will return all records in a single response:
223
+
224
+
```python
225
+
# Response structure without pagination
226
+
[
227
+
{"id": 1, "title": "Event 1", ...},
228
+
{"id": 2, "title": "Event 2", ...},
229
+
{"id": 3, "title": "Event 3", ...},
230
+
# ... all records
231
+
]
232
+
```
233
+
234
+
!!! warning "Performance Considerations"
235
+
Disabling pagination can lead to performance issues and large response payloads if your model has many records. Use this option only when:
236
+
237
+
- You have a small, bounded dataset (e.g., less than 100 records)
238
+
- You need to return all records for client-side processing
239
+
- You're certain the dataset will remain small
240
+
241
+
For large datasets, consider using pagination with a reasonable page size instead.
242
+
243
+
You can also disable pagination while still using filtering:
244
+
245
+
```python
246
+
from typing import Optional
247
+
from ninja import FilterSchema
248
+
249
+
classEventFilterSchema(FilterSchema):
250
+
title: Optional[str] =None
251
+
category: Optional[str] =None
252
+
253
+
@api_controller("/events")
254
+
classEventModelController(ModelControllerBase):
255
+
model_config = ModelConfig(
256
+
model=Event,
257
+
pagination=None, # No pagination, but filtering is still available
258
+
)
259
+
260
+
# Override list method to apply filtering manually
261
+
deflist(self, filters: EventFilterSchema):
262
+
queryset =self.model_config.model.objects.all()
263
+
queryset = filters.filter(queryset)
264
+
return [self.model_config.retrieve_schema.from_orm(obj) for obj in queryset]
265
+
```
266
+
209
267
## **Route Configuration**
210
268
211
269
You can customize individual route behavior using route info dictionaries. Each route type (`create_route_info`, `list_route_info`, `find_one_route_info`, `update_route_info`, `patch_route_info`, `delete_route_info`) accepts various configuration parameters.
0 commit comments