premises:
前提:
1) Environment: django 1.3, python 2.6, dev: across several platforms, prod: RHEL
1)环境:django 1.3, python 2.6, dev:跨几个平台,prod: RHEL
2) I would like to enable site staff to add users (from admin site). The way that they fill in on just ONE page 'username', 'email', 'password1', password2' AND 'first_name', 'last_name', 'phone', 'skype'. Click 'OK' and it's done.
2)我想让站点人员添加用户(来自管理站点)。他们只在一个页面上填写“用户名”、“电子邮件”、“password1”、“password2”和“first_name”、“last_name”、“phone”、“skype”。点击“OK”就完成了。
3) I've searched through the docs and web and found only quite outdated sources, non-working ideas and some sources which might work but deal with modifying django itself (which I found difficult to deploy and maintain)
3)我搜索了文档和web,发现只有相当过时的资源、无用的思想和一些可能有用的资源,但是需要修改django本身(我发现很难部署和维护这些资源)
What are your tips to do this job in most clean (easy, transparent, simple whatever) way?
你做这项工作的秘诀是什么?
So far, this article and it's comments was the most useful source I've found: http://scottbarnham.com/blog/2008/08/21/extending-the-django-user-model-with-inheritance/
到目前为止,这篇文章和它的评论是我找到的最有用的来源:http://scottbarnham.com/blog/2008/08/21/extendingthe -django-user-model- with_inheritance/。
thanks
谢谢
1 个解决方案
#1
2
I believe the recommended way of doing it is through UserProfile:
我认为推荐的方法是通过UserProfile:
#models.py
class MySiteProfile(models.Model):
user = models.ForeignKey(User, unique=True)
join_date = models.DateField()
# and whatever additional fields you want
#admin.py
from django.contrib.auth.admin import UserAdmin
admin.site.unregister(User)
class MyUserAdmin(UserAdmin):
inlines = [MySiteProfileInline, ]
admin.site.register(User, MyUserAdmin)
#inlines.py
class MySiteProfileInline(admin.TabularInline):
model = MySiteProfile
#1
2
I believe the recommended way of doing it is through UserProfile:
我认为推荐的方法是通过UserProfile:
#models.py
class MySiteProfile(models.Model):
user = models.ForeignKey(User, unique=True)
join_date = models.DateField()
# and whatever additional fields you want
#admin.py
from django.contrib.auth.admin import UserAdmin
admin.site.unregister(User)
class MyUserAdmin(UserAdmin):
inlines = [MySiteProfileInline, ]
admin.site.register(User, MyUserAdmin)
#inlines.py
class MySiteProfileInline(admin.TabularInline):
model = MySiteProfile