Hello,
I´m trying to custom admin in django 1.4. I went to docs, followed the
instructions, and worked.
The issue comes when I try to modify change_view, and find that inlines
does not work inside change_view function. My target is be able to allow
users to change only their username (from User model)
and their Profile information, but allow Admin user to access all the info.
My UserProfile model like this:
##models.py
##my smple profile
class UserProfile(models.Model):
user=models.OneToOneField(User)
extra_field=models.Charfield(max_length=100,blank=True)
My admin:
##admin.py
class UserProfileInline(admin.StackedInline):
model = UserProfile
class UserAdmin(admin.ModelAdmin):
##If I add inlines here, should work, but only for admin user...
##inlines = [UserProfileInline]
def change_view(self,reques,object_id):
try:
if request.user.is_superuser:
##here works for admin user
self.inlines = [UserProfileInline]
else:
##here I defined fieldsets, so, users only can modify its own
name
self.fieldsets =(
(None, {'fields':('username')}
)
##I thought that here, shoould add Profile fields to... but did
not work
self.inlines = [UserProfileInline]
return super(UserAdmin,self).change_view(request,object_id)
except:
raise PermissionDenied
Perhaps I miss something simple, or just did not work as expected...
any tips about how to achieve my target will be appreciate.
Thank you very much
--
You received this message because you are subscribed to the Google Groups
"Django users" group.
To view this discussion on the web visit
https://groups.google.com/d/msg/django-users/-/3QMFGYSqAnQJ.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/django-users?hl=en.