I have Admin User extended/subclassed by Teacher class.
How to prevent Teachers from seeing and changing other Teachers’ profile data and Teachers are able to change their own records/rows only? Thanks in advance!
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
I’m not sure I understand exactly what you’re trying to do, but if what’s in your mind is having the built-in user administration pages working slightly differently for Teacher users, then I believe you just have to extend
UserAdmin, and override thequerysetmethod.That will take care of disallowing Teachers to edit or delete other records, because if you look in the
ModelAdmincode,change_viewanddelete_viewmethod use the queryset returned fromquerysetmethod to get the object to change or delete.One more tweak is necessary, because the view used to change the password in
UserAdmindoesn’t use the same system as the others views to get the object to change. Just override it in your new class :After that, you just have to prevent Teachers to add new users, or delete their own record. Do that either using the default django’s permission framework, or by overriding
has_add_permissionandhas_delete_permissionmethods.Have a look in the
ModelAdminsource code if you want more info (incontrib/admin/options.py).