Cannot hide “Save and add another” button in Django Admin

前端 未结 6 1379
余生分开走
余生分开走 2021-01-03 05:54

I would like to hide all the \"Save\" buttons in Django\'s Admin\'s Change Form, for a specific model, when certain conditions are met. Therefore, I override the chang

6条回答
  •  爱一瞬间的悲伤
    2021-01-03 06:55

    You may override render_change_form method in ModelAdmin subclass. In this method obj is available as argument and you can check certain conditions.

    class OrderAdmin(admin.ModelAdmin):
    
        def render_change_form(self, request, context, add=False, change=False, form_url='', obj=None):
            context.update({
                'show_save': False,
                'show_save_and_continue': False,
                'show_delete': False
            })
            return super().render_change_form(request, context, add, change, form_url, obj)
    

提交回复
热议问题