1. Documentation
  2. Inlines
  3. Inline options

Available options for Unfold inlines

Display count for inlines

It is possible to display count of objects for inlines. You can set the count for an inline by providing show_count parameter which will run count() operation on the queryset. Be aware that this will run a query for each inline, so it is not recommended to use this for large querysets.

If you want to customize the count, you can implement get_count method on the inline where you can for example change the formatting. To change the variant of the count badge, you can implement get_count_variant method on the inline.

from django.utils.functional import cached_property

from unfold.admin import StackedInline


class SomeInline(StackedInline):
    model = SomeModel
    show_count = True  # This will run `count()`

    def get_count(self, request, obj):
        # You can customize the output of the count badge.
        return "1/2"

    def get_count_variant(self, request, obj):
        # Implement for custom variant
        return "primary" # danger, success, info, warning

Custom inline title

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.

from django.contrib.auth.models import User
from unfold.admin import TabularInline


class User(models.Model):
    # fields, meta ...

    def get_inline_title(self):
        return "Custom title"


class MyInline(TabularInline):
    model = User

Hide title row

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.

# admin.py

from django.contrib.auth.models import User
from unfold.admin import TabularInline


class MyInline(TabularInline):
    model = User
    hide_title = True

Collapsible StackedInline

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.

Key features of collapsible StackedInlines: - Records are collapsed by default, saving vertical space - Users can expand individual records as needed - Records containing validation errors automatically expand to highlight the issues - The collapsed state is preserved during form submission - Each record can be independently expanded or collapsed

To implement this feature, simply set the collapsible attribute to True in your StackedInline class:

from django.contrib.auth.models import User
from unfold.admin import StackedInline


class User(models.Model):
    inlines = [SomeInline]

class SomeInline(StackedInline):
    collapsible = True

© 2023 - 2026 Created by unfoldadmin.com. All rights reserved.