4

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 ?

Linh Nguyen
  • 3,452
  • 4
  • 23
  • 67
  • seems it is not possible with standard Django. see https://stackoverflow.com/questions/18390627/how-can-i-display-a-django-admin-inline-model-within-a-fieldset for workaround suggestions – Tryph Jan 31 '20 at 20:32

3 Answers3

0

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

Fabio Caccamo
  • 1,871
  • 19
  • 21
  • i had tried it but it doesn't seem to work with django 2.2. I see that django-suit and django-baton can have inline in tabs, i'm still reading over their code to see if it's possible – Linh Nguyen Feb 04 '20 at 15:46
  • Looking at the documentation it is possible: https://github.com/omji/django-tabbed-admin#configure-admin-tabs , the only limit is that you can display only 1 inline for tab. I prefer to use the default django admin and customize its theme using `django-admin-interface`, in this way all 3rd party libraries that improves the admin can be used. – Fabio Caccamo Feb 04 '20 at 16:19
  • If you check out django baton and i tried it you can have multiple inlines in 1 tab, but i don't want to use a theme as currently i only want the django admin overdrive way – Linh Nguyen Feb 04 '20 at 17:08
  • Do not use this; the project is abandoned (latest update from 2018) – Joren Oct 14 '21 at 19:17
0

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', ),
    }),
)
Linh Nguyen
  • 3,452
  • 4
  • 23
  • 67
0

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

Jayce
  • 116
  • 4