I'm new to Django. I'm working on a website that will only contain users as staff users. I'm the administrator. My plan is to register a user and give him his username and password to login; I want him only to be able to edit his profile to add more information, not to change existing attributes. How can I do that?
Asked
Active
Viewed 542 times
1 Answers
-1
The easiest way would probably be to create a appropriate ModelForm and a corresponding view, that checks that the instance the user want's to update is the own instance.
I you want to integrate this directly in the admin backend, you can also do this. The most djangoish way would propably be to create a own ModelAdmin
class for the User
that has the right methods overridden (see the methods startinghere). I think you should start with overriding has_change_permission
where you can check if the object the user tries to edit, is his own and return False otherwise.
To replace the standard User ModelAdmin you need to do a little fiddeling in the admin.py:
from django.contrib import admin
from django.contrib.auth.admin import UserAdmin
from django.contrib.auth.models import User
class MyUserAdmin(UserAdmin):
# add the code here
# deregister the standard AdminModel and register the own one
admin.site.unregister(User)
admin.site.register(User, MyUserAdmin)
(I'm using this code on a live site and it works create)

Martin Thurau
- 7,564
- 7
- 43
- 80