cómo controlar la eliminación en django_admin

i would like to control when it's possible to delete elements in django admin. first, i tried to override the delete method of models to raise integrity error. it's work but this exception in not catch by admin and don't show a nice message. in fact, if you run in production mode, all that it say is " a problem has occurred".

secondly, i put a form and the clean method. it don't work either. the clean method is run whenever you modify the element. not only when you delete.

so how to have a way to control deleting of element in django admin (and have a nice message saying why you can't delete it )?

preguntado el 09 de septiembre de 13 a las 23:09

1 Respuestas

No need, to show a message, the delete buttons won't show as long you use this:

class MyAdmin(ModelAdmin):

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

Respondido el 10 de Septiembre de 13 a las 04:09

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.
{"cc_re__cc_re__cc_by_sa_3_0": ["pan><span id=\"cn-notice-buttons\" class=\"cn-buttons-container\"><a href=\"javascript: accept_cookie(); void(0);\" id=\"cn-accept-cookie\" data-cookie-set=\"accept\" class=\"cn-set-cookie cn-button bootstrap button\" aria-label=\"Ok\">Ok</a><a href=\"https://stackovergo.com/es/cookies-policy\" target=\"_blank\" id=\"cn-more-info\" class=\"cn-more-info cn-button bootstrap button\" aria-label=\"Read more\">Leer m\u00e1s</a></span></div></div>\n\n</main>\n<footer>\n    <div class=\"footer-info\">stackovergo.com 2023, con licencia <a href=\"https://creativecommons.org/licenses/by-sa/3.0/\" target=\"_blank\">cc by-sa 3.0</a> con atribuci\u00f3n requerida. | <a href=\"https://stackovergo.com/es/privacy-policy\">Pol\u00edtica de privacidad</a> | <a href=\"https://stackovergo.com/es/cookies-policy\">Pol\u00edtica de Cookies</a></div>\n</footer>\n\n<script defer=\"\" src=\"https://stackovergo.com/assets/general.js\"></script>\n\n\n<script>\n    var request = \"q/5300505/how-to-control-delete-in-djangoadmin\";\n    var current_language = 'es';\n    var site_domain = 'stackovergo.com';\n    var site_link = 'https://stackovergo.com/es/';"]}