[Answered ]-How to show the list_display feature in Inline admin in django?

1👍

You can add extra fields to an inline by using a custom form like this:

from django import forms
from django.contrib import admin

from .models import CartItem, Cart


class CartItemForm(forms.ModelForm):
    class Meta:
        model = CartItem
        fields = ["field_1", "field_2", ...]  # all model fields to show

    extra_field = forms.CharField(max_length=5)  # example for an extra field


class CartItemInline(admin.StackedInline):
    model = CartItem


class CartInlineAdmin(admin.ModelAdmin):
    inlines = [
       CartItemInline,
    ]


admin.site.register(Cart, CartInlineAdmin)

Leave a comment