Odp: Re: Odp: Re: Django admin - how to hide some fields in User edit?

2011-07-05 Thread galgal
I made it in that way, and it works:
def get_fieldsets(self, request, obj=None):
if obj:
if request.user.id == 1:
return self.declared_fieldsets
else:
if obj.get_profile().type==1:
return (
(None, {'fields': ('username', 'password')}),
(_('Personal info'), {'fields': ('first_name', 
'last_name', 'email')}),
(_('Important dates'), {'fields': ('last_login', 
'date_joined')}),
)
else:
return (
(None, {'fields': ('username', 'password')}),
(_('Personal info'), {'fields': ('first_name', 
'last_name', 'email')}),
(_('Permissions'), {'fields': ('is_active', 
'is_staff', 'user_permissions')}),
(_('Important dates'), {'fields': ('last_login', 
'date_joined')}),
)
else:
return self.add_fieldsets

-- 
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/-/Mq--t4_P1qMJ.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Odp: Re: Odp: Re: Django admin - how to hide some fields in User edit?

2011-07-04 Thread galgal
That's my code now - how to hide groups for example?

admin.site.unregister(User)
class UserProfileInline(admin.StackedInline):
model = UserProfile
filter_horizontal = ('cities',)
extra = 1
max_num = 1
filter_horizontal = ('cities',)

class UserProfileAdmin(UserAdmin):
inlines = [UserProfileInline,]
list_filter = ('userprofile__type','userprofile__cities',)
search_fields = ['userprofile__type', 'username', 
'userprofile__cities__name', 'email', 'first_name', 'last_name',]

# show users list - if user_id=1 show all, else: show id's > 1
def queryset(self, request):
qs = super(UserProfileAdmin, self).queryset(request)
if request.user.id == 1:
return qs
return qs.filter(id__gt=1)

admin.site.register(User, UserProfileAdmin)

-- 
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/-/ZzrytaO1EOcJ.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.