# How to Disable some action and filed on Model Form on site admin

**URL:** <https://forum.djangoproject.com/t/how-to-disable-some-action-and-filed-on-model-form-on-site-admin/6397>\
**Category:** Using Django\
**Created:** [February 1, 2021, 4:01pm UTC](https://forum.djangoproject.com/t/how-to-disable-some-action-and-filed-on-model-form-on-site-admin/6397 "2021-02-01T16:01:51Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![technqvi](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/technqvi/32/1851_2.png) [@technqvi](https://forum.djangoproject.com/u/technqvi)\
**Post date:** [February 1, 2021, 4:01pm UTC](https://forum.djangoproject.com/t/how-to-disable-some-action-and-filed-on-model-form-on-site-admin/6397/1 "2021-02-01T16:01:51Z")

</div>

Hi

1. I want to disable delete and add an action for this model  
so this model can be only updated through this form on the admin site ( disable 1 and 2 in the picture)

2.Not allow to input data in Source Name Field ( 3 in the picture)

Please recommend any solution or link document to study how to customize the form in admin site like above.

 ![image](https://us1.discourse-cdn.com/flex026/uploads/djangoproject/original/2X/2/2d69ab0bed5cdab7751b2494bf56b4606d4c0f2e.png)

Thank you for any help  
Pongthorn

---

<div class="post-metadata">

**Author:** ![marcorichetta](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/marcorichetta/32/26473_2.png) [@marcorichetta](https://forum.djangoproject.com/u/marcorichetta)\
**Post date:** [February 1, 2021, 4:13pm UTC](https://forum.djangoproject.com/t/how-to-disable-some-action-and-filed-on-model-form-on-site-admin/6397/2 "2021-02-01T16:13:18Z")

</div>

For #1 and #2 you’ll need to override `has_add_permission` and [`has_delete_permission`](https://docs.djangoproject.com/en/3.1/ref/contrib/admin/#django.contrib.admin.ModelAdmin.has_delete_permission) to check if the user has permission to do those actions. If not, the admin will not show the + and the delete button.

[SO example](https://stackoverflow.com/a/55560454/6389248)

For #3 you can use [ModelAdmin.get\_form](https://docs.djangoproject.com/en/3.1/ref/contrib/admin/#django.contrib.admin.ModelAdmin.get_form) method to specify the form to use admin.

---

<div class="post-metadata">

**Author:** ![technqvi](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/technqvi/32/1851_2.png) [@technqvi](https://forum.djangoproject.com/u/technqvi)\
**Post date:** [February 2, 2021, 4:36pm UTC](https://forum.djangoproject.com/t/how-to-disable-some-action-and-filed-on-model-form-on-site-admin/6397/3 "2021-02-02T16:36:33Z")

</div>

Hi, thank you for a quick reply.  
I try to do as your recommendation , it is ok for my three requirements.  
it is great but requirement#3 _I just apply readonly\_fields_ ( not use you can use [ModelAdmin.get\_form](https://docs.djangoproject.com/en/3.1/ref/contrib/admin/#django.contrib.admin.ModelAdmin.get_form)) I don’t know how to do in the next step.

**I have one additional question**  
_Type name field can be enabled in Add- Mode but read only in Change-Mode_  
_How can I do?_

Once I did, this field disappears. as I understand because it is set as read\_only

 ![image](https://us1.discourse-cdn.com/flex026/uploads/djangoproject/original/2X/b/b6e75eedd659fb0029b94db8ff79eeb43789e4e4.png)

```auto
@admin.register(CostType)
class CostTypeAdmin(admin.ModelAdmin):
    actions =None
    readonly_fields = ('type_name',)
    search_fields = ['type_name']
    # def has_add_permission(self, request, obj=None):
    # return False
    def has_delete_permission(self, request, obj=None):
        return False

```

---

<div class="post-metadata">

**Author:** ![marcorichetta](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/marcorichetta/32/26473_2.png) [@marcorichetta](https://forum.djangoproject.com/u/marcorichetta)\
**Post date:** [February 2, 2021, 5:43pm UTC](https://forum.djangoproject.com/t/how-to-disable-some-action-and-filed-on-model-form-on-site-admin/6397/4 "2021-02-02T17:43:06Z")

</div>

If I understand what you’re trying to do you could use `get_readonly_fields`. ([Source](https://books.agiliq.com/projects/django-admin-cookbook/en/latest/uneditable_existing.html)) ([Django docs](https://docs.djangoproject.com/en/3.1/ref/contrib/admin/#django.contrib.admin.ModelAdmin.get_readonly_fields))

```auto
def get_readonly_fields(self, request, obj=None):
    if obj:
        # On update type_name will be read-only
        return ["type_name"]
    else:
        # On creation all fields will be editable
        return []

```

---

<div class="post-metadata">

**Author:** ![technqvi](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/technqvi/32/1851_2.png) [@technqvi](https://forum.djangoproject.com/u/technqvi)\
**Post date:** [February 3, 2021, 4:48am UTC](https://forum.djangoproject.com/t/how-to-disable-some-action-and-filed-on-model-form-on-site-admin/6397/5 "2021-02-03T04:48:37Z")

</div>

Thank you for your great support.  
You help me save time to customize Django admin very much much

The D[jango Admin Cookbook](https://books.agiliq.com/projects/django-admin-cookbook/en/latest/index.html) is very helpful for me to study more apart from [The Django admin site](https://books.agiliq.com/projects/django-admin-cookbook/en/latest/uneditable_existing.html)

I got things done because of you.
