Unfold allows you to sort inlines by adding a ordering_field
to the inline class. This field will be used to sort the inlines in the admin panel. There is also an option to hide the ordering field from the UI by setting hide_ordering_field
to True
.
PositiveIntegerField
with db_index=True
# admin.py
from unfold.admin import TabularInline
from .models import User
# This works for StackedInline as well
class MyInline(TabularInline):
model = User
ordering_field = "weight"
hide_ordering_field = True
list_display = ["email", "weight"] # Weight is mandatory field
In order to use the sorting functionality, you need to create a model field with a PositiveIntegerField
type and set db_index=True
where the Unfold admin will store the sorting order.
# models.py
from django.db import models
from django.utils.translation import gettext_lazy as _
class User(models.Model):
weight = models.PositiveIntegerField(_("weight"), default=0, db_index=True)
Django admin theme built with Tailwind CSS to bring modern look and feel to your admin interface. Already contains several built-in features for smooth developer experience.
© 2023 - 2024 Created by unfoldadmin.com. All rights reserved.