Skip to content

Commit c939fce

Browse files
authored
feat: paginated inlines (#1373)
1 parent fa7d5db commit c939fce

File tree

26 files changed

+1075
-646
lines changed

26 files changed

+1075
-646
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,11 @@ Unfold Studio is a theme customizer for Django admin that helps you create a bra
2626

2727
## Fresh Features & Enhancements
2828

29+
- **Paginated inlines:** Break down large record sets into pages within inlines for better admin performance
2930
- **Conditional fields:** Show or hide fields dynamically based on the values of other fields in the form
3031
- **Infinite paginator:** Efficiently handle large datasets with seamless pagination that reduces server load
3132
- **Checkbox & radio filters:** Enhanced filter options with checkbox and radio interfaces for intuitive filtering
3233
- **Site dropdown:** Configurable dropdown menu in the header area for managing custom navigation links
33-
- **Dropdown actions:** Organize action items in customizable dropdown menus
3434

3535
## Core Features & Capabilities
3636

@@ -50,6 +50,7 @@ Unfold Studio is a theme customizer for Django admin that helps you create a bra
5050
- **Sortable inlines:** Allow sorting inlines by dragging and dropping
5151
- **Environment label:** Distinguish between environments by displaying a label
5252
- **Nonrelated inlines:** Display nonrelated models as inlines in the change form
53+
- **Paginated inlines:** Break down large record sets into pages within inlines for better admin performance
5354
- **Favicons:** Built-in support for configuring various site favicons
5455
- **Themes:** Allow customization of color scheme, background color, border radius, and more
5556
- **Font colors:** Adjust font colors for better readability

docs/inlines/options.md

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,17 @@ description: Customize Django Unfold inline options including title customizatio
66

77
# Available options for Unfold inlines
88

9-
By default, each inline row's title is derived from the model's `__str__` implementation. However, Unfold provides the ability to customize this title specifically for inlines by implementing a `get_inline_title` method on the model, which can return a custom title that will only be used in inline contexts.
9+
## Custom inline title
10+
11+
By default, each inline row's title is derived from the model's `__str__` implementation. However, Unfold provides the ability to customize this title specifically for inlines by implementing a `get_inline_title` method on the model. This method can return a custom title that will only be used in inline contexts, allowing for more descriptive and context-specific labels.
1012

1113
```python
1214
from django.contrib.auth.models import User
1315
from unfold.admin import TabularInline
1416

1517

1618
class User(models.Model):
17-
# fiels, meta ...
19+
# fields, meta ...
1820

1921
def get_inline_title(self):
2022
return "Custom title"
@@ -26,7 +28,7 @@ class MyInline(TabularInline):
2628

2729
## Hide title row
2830

29-
You can hide the title row for both `StackedInline` and `TabularInline` by setting the `hide_title` attribute to `True`. Note that for `StackedInline`, the delete permission (`can_delete`) must be disabled to hide the title row since the delete checkbox is contained within it.
31+
You can hide the title row for both `StackedInline` and `TabularInline` by setting the `hide_title` attribute to `True`. This feature is particularly useful when you want to create a more compact and streamlined interface. Please note that for `StackedInline`, the delete permission (`can_delete`) must be disabled to hide the title row, as the delete checkbox is contained within it.
3032

3133
```python
3234
# admin.py
@@ -39,3 +41,28 @@ class MyInline(TabularInline):
3941
model = User
4042
hide_title = True
4143
```
44+
45+
## Collapsible StackedInline
46+
47+
Unfold enhances the `StackedInline` functionality by introducing a collapsible mode. When enabled, this feature allows you to display multiple records in a space-efficient manner by defaulting to a collapsed state. This is particularly useful when dealing with forms that contain numerous inline entries, as it helps maintain a clean and organized interface.
48+
49+
Key features of collapsible StackedInlines:
50+
- Records are collapsed by default, saving vertical space
51+
- Users can expand individual records as needed
52+
- Records containing validation errors automatically expand to highlight the issues
53+
- The collapsed state is preserved during form submission
54+
- Each record can be independently expanded or collapsed
55+
56+
To implement this feature, simply set the `collapsible` attribute to `True` in your StackedInline class:
57+
58+
```python
59+
from django.contrib.auth.models import User
60+
from unfold.admin import StackedInline
61+
62+
63+
class User(models.Model):
64+
inlines = [SomeInline]
65+
66+
class SomeInline(StackedInline):
67+
collapsible = True
68+
```

docs/inlines/paginated.md

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
---
2+
title: Paginated inlines
3+
order: 4
4+
description: Implement paginated inlines in Django Unfold to efficiently manage large datasets by breaking down inline records into manageable pages, with customizable per-page settings and support for multiple paginated inlines.
5+
---
6+
7+
Pagination on inlines can be enabled by providing the `per_page` property in the inline class. This feature is particularly useful when dealing with models that have a large number of related objects, as it helps improve page load times and provides a better user experience by breaking down the data into manageable chunks. The `per_page` property accepts an integer value that determines how many inline records will be displayed on each page.
8+
9+
[![Paginated inlines](/static/docs/inlines/paginated-inlines.webp)](/static/docs/inlines/paginated-inlines.webp)
10+
11+
It is possible to define multiple paginated inlines on the same page without any conflicts. This flexibility allows administrators to work with complex models that have multiple relationships, each potentially containing numerous records. Django Unfold handles the pagination state independently for each inline, ensuring that navigating through one inline's pages doesn't affect the pagination state of other inlines on the same admin page.
12+
13+
Each inline has its own unique query parameter in the URL to maintain its pagination state. This implementation ensures that when users navigate between pages of different inlines, the system can track and maintain the current page for each inline separately. The unique query parameters are automatically generated and managed by Django Unfold, so developers don't need to worry about potential conflicts or parameter naming conventions.
14+
15+
AJAX pagination is not currently supported for inlines. This means that when users click on pagination links, the entire admin page will reload to display the new set of records. While this approach may not be as seamless as AJAX-based pagination, it ensures compatibility with Django's existing admin infrastructure and maintains the reliability of the admin interface functionality.
16+
17+
If inline records fit on only one page, no pagination controls will be displayed to keep the interface clean and uncluttered. Django Unfold automatically detects when the total number of records is less than or equal to the specified `per_page` value and hides the pagination controls accordingly. This intelligent behavior prevents unnecessary UI elements from appearing when they serve no functional purpose.
18+
19+
```python
20+
from unfold.admin import StackedInline, TabularInline, GenericStackedInline, GenericTabularInline
21+
from unfold.contrib.inlines.admin import NonrelatedStackedInline, NonrelatedTabularInline
22+
23+
24+
############################################
25+
# Regular inlines
26+
############################################
27+
class SomeStackedInline(StackedInline):
28+
model = YourModel
29+
per_page = 10
30+
31+
class SomeTabularInline(TabularInline):
32+
model = YourModel
33+
per_page = 10
34+
35+
############################################
36+
# Generic inlines
37+
############################################
38+
class SomeGenericStackedInline(GenericStackedInline):
39+
model = YourModel
40+
per_page = 10
41+
42+
class SomeGenericTabularInline(GenericTabularInline):
43+
model = YourModel
44+
per_page = 10
45+
46+
############################################
47+
# Nonrelated inlines
48+
############################################
49+
class SomeNonrelatedStackedInline(NonrelatedStackedInline):
50+
model = YourModel
51+
per_page = 10
52+
53+
class SomeNonrelatedTabularInline(NonrelatedTabularInline):
54+
model = YourModel
55+
per_page = 10
56+
```

0 commit comments

Comments
 (0)