Django admin StackedInline in custom tab

Question:

I currently having problem trying to figure out how can i put 3 inline in a single tab on the change view.

I currently have the following admin for one of the view as follow:

class UserAdminCustom(admin.ModelAdmin):
    list_display = ('id', 'email', 'status', 'created')
    verbose_name = "General"
    exclude = ('password', 'last_login', 'is_superuser', 'is_staff', 'groups',
               'user_permissions', 'username', 'first_name', 'last_name', 'is_active', 'date_joined', 'modified')

    inlines = [
        UserKycInline, UserWalletInline, UserBankInline, CardBindingInline, TopUpsInline, TransfersInline, WithdrawalsInline
    ]

    def get_queryset(self, request):
        qs = super(UserAdminCustom, self).get_queryset(request)
        return qs.filter(is_staff=False)

    def get_readonly_fields(self, request, obj=None):
        return ('id', 'created', 'modified')



admin.site.register(User, UserAdminCustom)

i currently want TopUpsInline, TransfersInline, WithdrawalsInline to all be in 1 tab name transactions . I figure i would use fieldsets but it only work on the user fields and can’t be apply to the Inline.

Is there anyway i can show 3 inline in 1 custom tab on change view ?

Asked By: Linh Nguyen

||

Answers:

It is not possible with the standard django admin, I suggest you to try django-tabbed-admin.

Answered By: Fabio Caccamo

I found that django-baton template does support custom form tab and i managed to get 3 inlines in a single tab

https://django-baton.readthedocs.io/en/latest/form_tabs.html

inlines = [
    UserKycInline, UserWalletInline, UserBankInline, CardBindingInline, TopUpsInline, TransfersInline, WithdrawalsInline,
]

fieldsets = (
    ('General', {
        'fields': ('id', 'uid', 'phone_number', 'nickname', 'status', 'eth_address', 'evt_address', 'created', 'modified',),
        'classes': ('baton-tabs-init', 'baton-tab-group-fs-kyc--inline-userkyc', 'baton-tab-group-fs-wallets--inline-user_wallet', 'baton-tab-group-fs-banks--inline-user_bank', 'baton-tab-group-fs-cards--inline-user_binding', 'baton-tab-group-fs-transactions--inline-user_toptup--inline-transfers--inline-user_transfer--inline-user_withdrawal', ),
    }),
    ('KYC', {
        'fields': (),
        'classes': ('tab-fs-kyc', ),
    }),
    ('WALLETS', {
        'fields': (),
        'classes': ('tab-fs-wallets', ),
    }),
    ('BANKS', {
        'fields': (),
        'classes': ('tab-fs-banks', ),
    }),
    ('CARDS', {
        'fields': (),
        'classes': ('tab-fs-cards', ),
    }),
    ('Transactions', {
        'fields': (),
        'classes': ('tab-fs-transactions', ),
    }),
)
Answered By: Linh Nguyen

You can try https://github.com/cuongnb14/django-admin-extended. Just install follow instructions at https://github.com/cuongnb14/django-admin-extended#readme

Default it slipt each inline model to one tab, if you want all inline models to only one tab you can modify code at admin_extended/templates/admin/change_form.html. It uses jquery-ui and you can easy to do it. Image demo

Answered By: Jayce
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.