Skip to content

Commit

Permalink
Fix: fix get_delete_objects call
Browse files Browse the repository at this point in the history
Refs #135
  • Loading branch information
last-partizan committed Mar 29, 2020
1 parent 9f0ccc5 commit c8cc0f7
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 14 deletions.
4 changes: 1 addition & 3 deletions django_mongoengine/mongo_admin/actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,11 @@ def _delete_selected(modeladmin, request, queryset):
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.
# TODO: Permissions would be so cool...
deletable_objects, perms_needed, protected = get_deleted_objects(
queryset, opts, request.user, modeladmin.admin_site, using)
queryset, request, modeladmin.admin_site)

# The user has already confirmed the deletion.
# Do the deletion and return a None to display the change list view again.
Expand Down
13 changes: 2 additions & 11 deletions django_mongoengine/mongo_admin/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -396,19 +396,10 @@ def delete_view(self, request, object_id, extra_context=None):
{'name': force_text(opts.verbose_name), 'key': escape(object_id)}
)

from django.db import router
using = router.db_for_write(self.model)

# Populate deleted_objects, a data structure of all related objects that
# will also be deleted.
try:
# Django 2.x/3.x
(deleted_objects, model_count, perms_needed, protected) = get_deleted_objects(
[obj], request, self.admin_site)
except TypeError:
# Django 1.x
(deleted_objects, model_count, perms_needed, protected) = get_deleted_objects(
[obj], opts, request.user, self.admin_site, using)
(deleted_objects, model_count, perms_needed, protected) = get_deleted_objects(
[obj], request, self.admin_site)

if request.POST: # The user has already confirmed the deletion.
if perms_needed:
Expand Down

0 comments on commit c8cc0f7

Please sign in to comment.