Paginated inlines allow you to split large sets of related objects across multiple pages, improving performance and user experience when dealing with models that have many related objects.Documentation Index
Fetch the complete documentation index at: https://mintlify.com/unfoldadmin/django-unfold/llms.txt
Use this file to discover all available pages before exploring further.
Overview
When a model has hundreds or thousands of related objects, displaying all of them at once can slow down page load times and overwhelm users. Pagination solves this by displaying a manageable subset of objects per page.
Basic Setup
Enable pagination by setting theper_page attribute on your inline class:
admin.py
Setting
per_page automatically enables pagination for the inline. The system uses Django’s built-in Paginator class.How It Works
Unfold’s pagination system:- Uses
PaginationInlineFormSetorPaginationGenericInlineFormSet(set automatically) - Creates a paginator for the inline’s queryset
- Displays only the current page’s objects
- Adds pagination controls below the inline
admin.py
Custom Formset
The formset is automatically set to handle pagination, but you can customize it if needed:admin.py
Generic Inline Pagination
Pagination works with generic inlines as well:admin.py
Generic inlines automatically use
PaginationGenericInlineFormSet when per_page is set.Page Navigation
The pagination controls allow users to:- Navigate to the next/previous page
- Jump to a specific page number
- See the total number of pages
Combining with Tabs
Paginated inlines work seamlessly with inline tabs:admin.py
Each tabbed inline maintains its own pagination state independently. Learn more in Inline Tabs.
Performance Optimization
Optimize paginated inlines for better performance:admin.py
Dynamic Per-Page Values
Set the per-page value dynamically based on user preferences or other criteria:admin.py
Pagination with Sortable Inlines
You can combine pagination with sortable functionality, though sorting is limited to the current page:admin.py
Learn more about sortable inlines in Sortable Inlines.
Handling Forms on Paginated Inlines
When a form has errors, the page containing the error is automatically displayed:admin.py
The pagination system preserves the current page in POST requests, ensuring users stay on the same page after saving.
Best Practices
Choose appropriate page sizes
Choose appropriate page sizes
Select a
per_page value based on your use case:- Small forms (few fields): 15-25 items per page
- Large forms (many fields): 5-10 items per page
- Simple lists: 25-50 items per page
Set extra=0 for paginated inlines
Set extra=0 for paginated inlines
When using pagination, set Users can add new items via the “Add another” button.
extra=0 to avoid empty forms:Optimize queries
Optimize queries
Always optimize your querysets for paginated inlines:
Consider readonly fields
Consider readonly fields
For view-heavy use cases, make most fields readonly:
Technical Details
Number of inline objects to display per page. When set, automatically enables pagination using
PaginationInlineFormSet.unfold.forms.PaginationFormSetMixin- Base mixin for pagination logicunfold.forms.PaginationInlineFormSet- Formset for regular inlinesunfold.forms.PaginationGenericInlineFormSet- Formset for generic inlines
get_pagination_key()- Returns the query parameter name ({prefix}-page)get_page_num()- Extracts the current page number from requestget_page()- Returns the Page object for the current page
Related Features
Inlines Overview
Learn about inline basics
Sortable Inlines
Add drag-and-drop ordering
Inline Tabs
Organize inlines with tabs
Nonrelated Inlines
Work with non-related objects