def delete_selected(modeladmin, request, queryset): opts = modeladmin.model._meta if not modeladmin.has_delete_permission(request): raise PermissionDenied using = router.db_for_write(modeladmin.model) # Populate deletable_objects, a data structure of all related objects that # will also be deleted. deletable_objects, model_count, perms_needed, protected = get_deleted_objects( queryset, opts, request.user, modeladmin.admin_site, using) # The user has already confirmed the deletion. # Do the deletion and return a None to display the change list view again. if request.POST.get('post'): if perms_needed: raise PermissionDenied n = queryset.count() if n: for obj in queryset: obj_display = force_text(obj) modeladmin.log_deletion(request, obj, obj_display) remove_program_elasticsearch(program_id=obj.id) queryset.delete() modeladmin.message_user( request, _("Successfully deleted %(count)d %(items)s.") % { "count": n, "items": model_ngettext(modeladmin.opts, n) }, messages.SUCCESS) # Return None to display the change list page again. return None else: return django_delete_selected(modeladmin, request, queryset)
def delete_selected(modeladmin, request, queryset): # wrap regular django delete_selected to check permissions for each object for obj in queryset: if not modeladmin.has_delete_permission(request, obj): raise PermissionDenied return django_delete_selected(modeladmin, request, queryset)
def delete_selected(modeladmin, request, queryset): if issubclass(modeladmin.model, models.Model): return django_delete_selected(modeladmin, request, queryset) else: return _delete_selected(modeladmin, request, queryset)
def delete_selected(self, request, queryset): for obj in queryset: obj.image.delete() return django_delete_selected(self, request, queryset)