Remove “add another” in Django admin screen

后端 未结 10 600
孤独总比滥情好
孤独总比滥情好 2020-12-05 13:34

Whenever I\'m editing object A with a foreign key to object B, a plus option \"add another\" is available next to the choices of object B. How do I remove that option?

10条回答
  •  星月不相逢
    2020-12-05 14:17

    Though most of the solutions mentioned here work, there is another cleaner way of doing it. Probably it was introduced in a later version of Django, after the other solutions were presented. (I'm presently using Django 1.7)

    To remove the "Add another" option,

    class ... #(Your inline class)
    
        def has_add_permission(self, request):
            return False
    

    Similarly if you want to disable "Delete?" option, add the following method in Inline class.

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

提交回复
热议问题