Search code examples
djangodjango-adminadmin

In Django admin how can i hide or remove the Pencil, "+" and "x"?


I can hide all the options in the model base, but is not necessary, on the relation i can't do that i think that exist a simple form (not with css) to remove or hide it

These are

Thanks


Solution

  • I agree with Ivan Camilito Ramirez Verdes's solution :

    class MyModelAdmin(admin.ModelAdmin):
    
        list_display = (
            'my_field',
        )
    
        def get_form(self, request, obj=None, **kwargs):
            form = super().get_form(request, obj, **kwargs)
            form.base_fields['my_field'].widget.can_change_related = False
            form.base_fields['my_field'].widget.can_add_related = False
            return form