Django superuser doesn't have permission to delete models
Asked Answered
S

2

12

I am working on upgrading a Django website from Django 1.8 to Django 2.2 and have come across a problem when trying to delete an object from the Django admin changelist view. When I try to delete an object, I am shown a screen with the words "Deleting the selected Records would result in deleting related objects, but your account doesn't have permission to delete the following types of objects". The problem is, I am a superuser and should have permission to delete any object I want, or so I thought.

I have read a decent amount of documentation on Django upgrades and permissions of superusers, however I haven't stumbled across anything that helps me (I could be missing something though). I have tried creating a new superuser just in case, still the same message occurs though. Anyway, Does anyone have any idea why this could be happening?

Note: I can't show any code because I am working for a company and I signed an NDA. Just some help pointing me in the right direction would be appreciated.

Sabinasabine answered 18/9, 2019 at 16:11 Comment(3)
There is a package, github.com/django-guardian/django-guardian. Which allow you to restrict permission on your model object. That might make you unable to delete models. I might need to take at the modeladmin also, make sure that there is no locked action in there.Nason
check if the has_delete_permission method has been overridden in the model admin.Oosperm
Thanks everyone! dirkgroten was right and it turns out the has_delete_permission was overridden! Thanks for your help!Sabinasabine
S
15

For anyone else who stumbles across this problem, dirkgroten was right and it turns out the has_delete_permission was overridden! Thanks for your help dirkgroten!

Sabinasabine answered 18/9, 2019 at 17:0 Comment(0)
R
0

OPENEDX If You are facing This issue then do this thing from the backend.

Cannot delete user Deleting the selected user would result in deleting related objects, but your account doesn't have permission to delete the following types of objects: course enrollment

Open Mysql In EDX server like AWS then get user id based on username then student_courseenrollment delete from this user

Example

select id from auth_user where username = 'exampleusername'

delete from student_courseenrollment where user_id = get user_id from 1 query set;

like delete from student_courseenrollment where user_id = 123;
Roily answered 2/5, 2022 at 9:40 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.