开发者

add an image field to admin.auth admin site in django

Hi ive not be able to find any one trying to solve this issue yet so i thought id ask the question here. Basically im trying to add an image field to the admin.auth users admin site that relates to my userprofile model.

Aswell as users that register to the site, the admins need to be able to specify a profile picture when the cre开发者_Python百科ate a user in the admin site that will be used for posts they make to news and blogs etc.

Is this at all possible, i have the userprofile model working which will allow me to add the image but i want to include this in the admin user panel when an admin creates a new user.

Any help is greatly appreciated!!

Thanks in advance


You can add your UserProfile (with the extra image field) as an inline to the User adminModel. So when you go to the admin.auth panel to add a new user, there will be an inline below it with all the UserProfile fields.

Something like this should do it (in admin.py of whatever app your userprofile is in):

from django.contrib.auth.admin import UserAdmin
from django.contrib.auth.models import User
from django.contrib import admin

class UserProfileInline(admin.StackedInline):
    model = UserProfile

class UserModelAdmin(UserAdmin):
    inlines = [UserProfileInline,]

admin.site.unregister(User)
admin.site.register(User,UserModelAdmin)
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜