Re: How do wire Userprofile to UserAdmin ?

2008-12-09 Thread Timboy

The problem with this solution is that you are unable to sort and/or
filter by anything you "wire" to the User admin page. #9463 is one I
have posted a bit ago.

On Dec 9, 9:43 am, "Ronny Haryanto" <[EMAIL PROTECTED]> wrote:
> On Tue, Dec 9, 2008 at 8:58 PM, mahesh <[EMAIL PROTECTED]> wrote:
> > How do wire Userprofile to UserAdmin ?
>
> Here's one way to do it:
>
> # admin.py
> from django.contrib import admin
> from django.contrib.auth.admin import UserAdmin
> from django.contrib.auth.models import User
>
> from myproj.myapp.models import UserProfile
>
> class UserProfileAdminInline(admin.TabularInline):
>     model = UserProfile
>
> class NewUserAdmin(UserAdmin):
>     inlines = [UserProfileAdminInline]
>
> admin.site.unregister(User)
> admin.site.register(User, NewUserAdmin)
>
> Ronny
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
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
-~--~~~~--~~--~--~---



Re: How do wire Userprofile to UserAdmin ?

2008-12-09 Thread Ronny Haryanto

On Tue, Dec 9, 2008 at 8:58 PM, mahesh <[EMAIL PROTECTED]> wrote:
> How do wire Userprofile to UserAdmin ?

Here's one way to do it:

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

from myproj.myapp.models import UserProfile

class UserProfileAdminInline(admin.TabularInline):
model = UserProfile

class NewUserAdmin(UserAdmin):
inlines = [UserProfileAdminInline]

admin.site.unregister(User)
admin.site.register(User, NewUserAdmin)

Ronny

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
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
-~--~~~~--~~--~--~---



How do wire Userprofile to UserAdmin ?

2008-12-09 Thread mahesh

UserProfile

How do wire Userprofile to UserAdmin ?

I want to add some more fields to user class. I have added one class
in polls/admin.py (polls being my app) and added following attribute
in settings.py

>> code snippet <<

AUTH_PROFILE_MODULE='polls.MySiteProfile'

model.py >>>>
gender = (
('M', 'Male'),
('F', 'Female'),
)

user_kind = (('MCH', 'Machine User'),
 ('HMN', 'Human User')
)


class MySiteProfile(models.Model):
gender = models.CharField(max_length=1, choices=gender)
user_kind = models.CharField(max_length=3, choices=user_kind)
user = models.ForeignKey(User,unique=True)


In Django Shell >>>

from django.contrib.auth.models import User
from mysite.polls import model, admin


u = User.objects.get(pk=1)
msp = sp = models.MySiteProfile(user=u, gender='M', user_kind='MCH')

u.get_profile().gender # Returns “M” No problem

Question

How do I wire this in admin page ?

Thank You in advance

[EMAIL PROTECTED]

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
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
-~--~~~~--~~--~--~---