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

前端 未结 6 1390
余生分开走
余生分开走 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:50

    If no one is against, then I publish my little hack. This can be inserted anywhere and called up from the settings file (preferably at the very end).

    # Hide "save_and_add_another" button
    from django.contrib.admin.templatetags import admin_modify
    
    submit_row = admin_modify.submit_row
    def submit_row_custom(context):
        ctx = submit_row(context)
        ctx['show_save_and_add_another'] = False
        return ctx
    admin_modify.submit_row = submit_row_custom
    

提交回复
热议问题