[Fixed]-How can I display form in django admin depending on user, Django

1👍

You need to customize corresponding ModelAdmin for your model.

admin.py

from django.contrib import admin
from .forms import SuperuserForm, OtherForm


class MyAdmin(admin.ModelAdmin):
    def get_form(self, request, obj=None, **kwargs):
        if request.user.is_superuser():
            kwargs['form'] = SuperUserForm
        else:
            kwargs['form'] = OtherUserForm

        return super(MyAdmin, self).get_form(request,obj=obj,**kwargs)
👤kia

Leave a comment