2
votes

premises:

1) Environment: django 1.3, python 2.6, dev: across several platforms, 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.

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)

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/

thanks

1
I don't think inheritance from User model is advised by any official django documentation, is it? - Paulo Scardine
Yes, they don't speak too much about it. That's why I'm asking. - tookanstoken

1 Answers

2
votes

I believe the recommended way of doing it is through 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