Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

234
Vistas
How can I disable deletion of inline objects when using django-reverse-admin?

This is my ModelAdmin:

class ComputerAdmin(ReverseModelAdmin):
    list_display = ('employee', 'ip', 'mac', 'name', 'hardware')
    list_filter = ('employee__branch', )
    inline_type = 'tabular'
    inline_reverse = ['hardware', ]
    show_full_result_count = False

This is how it shows when adding a new computer:

Enter image description here

As you can see, I don't want to have the delete column and delete icon, because I have a foreign key so only one element is allowed. How can I do that?

Does django-reverse-admin have anything like has_delete_permisison for inlines only and not the whole ModelAdmin? I have already searched in documentation with no results, which is why I am posting here.

I updated my code as below:

class HardwareInline(admin.TabularInline):

    model = Hardware

    def has_delete_permission(self, request, obj=None):
        return False

class EmployeeAdmin(admin.ModelAdmin):

    list_display = ('group', 'branch', 'name')
    list_filter = ('group', )

class ComputerAdmin(ReverseModelAdmin):

    list_display = ('employee', 'ip', 'mac', 'name', 'hardware')
    list_filter = ('employee__group', 'employee__branch', )
    inline_type = 'tabular'
    inline_reverse = [ { 'field_name': 'hardware', 'admin_class': HardwareInline } ]

The delete column disappeared from inline, but I get a delete button under it:

Enter image description here

over 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

We can find the answer from this GitHub issue:

You need to explicitly create an inline, and add a has_delete_permission method to it:

class HardwareInline(admin.TabularInline):
    model = Hardware

    def has_delete_permission(self, request, obj=None):
        return False

And then in your ReverseModelAdmin, you need to specify the 'admin_class':

class ComputerAdmin(ReverseModelAdmin):
    list_display = ('employee', 'ip', 'mac', 'name', 'hardware')
    list_filter = ('employee__group', 'employee__branch')
    inline_type = 'tabular'
    inline_reverse = [
        {'field_name': 'hardware', 'admin_class': HardwareInline},
    ]

This should hide the "Delete" checkbox.

over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda