我必须覆盖管理员的删除方法,如下所示:
def fully_delete_selected_photos(self, request, queryset):
# Code to do my specific delete method.
fully_delete_selected_photos.short_description = "Delete Selected Photos"
class VehiclePhotoAdmin(admin.ModelAdmin):
search_fields = ('listing_id',)
list_display = ('listing_id', 'disp_VehiclePhoto')
actions = [fully_delete_selected_photos]
def get_actions(self, request):
actions = super(VehiclePhotoAdmin, self).get_actions(request)
del actions['delete_selected']
return actions
这很好但我丢失了删除的确认。因此,当用户选择我的"删除所选照片"选项它立即通过删除。我怎样才能对被覆盖的删除进行某种确认?我对管理员中的视图重定向感到困惑。
感谢您的时间!
答案 0 :(得分:0)
您可以在fully_delete_selected_photos方法中返回HttpResponseRedirect,并创建自定义视图,即从admin继承模板,并获取queryset参数,并列出所有选定的照片。 但是如果你想简化它,可以在管理视图中添加一些JavaScript。