문제

I am using django-guardian for giving role based permission and django-userena for user profiling. I have three kind of users Admin, sub-admin, employee. Admin can add sub-admin and sub-admin can add employees. I have created three groups in guardian for three user types. When user signup I assign that user an employee group.

class Profile(UserenaBaseProfile):
    class Meta:
    permissions = ( 
                ( "add_admin", "Can add admin" ),
                ( "add_subadmin", "Can add sub admin" ),
                ( "add_employee", "Can add employee" ),
            )
    user = models.OneToOneField(User,
                            unique=True,
                            verbose_name='user',
                            related_name='profile')
    first_name = models.CharField('First name',max_length=100,blank=False,null=False)
    def save(self, *args, **kwargs):
        super(Profile, self).save(*args, **kwargs)
        employee_group = Group.objects.get('employee')
        self.groups.add(employee_group)

I want to use the Django Admin and give Admin and sub-admin the ability to change the user's group.

How can I add the drop down or radio buttons in the Admin panel using AdminModel so that I can change the user's group. Or is there any better approach to do that.

도움이 되었습니까?

해결책

You looking for Admin actions, You have to write some custom admin actions.

Update

When you creating admin you can check if current request.user is able to see that actions. We can say like, If user is not a admin then custom action method should return None or just pass. There is an app for getting current user anywhere in the code, When you don't have access to your current user request, it's called django-cuser. It would be suitable for you case where you need to determine whether use is admin or sub-admin to make custom action available for him.

Start from Conditionally enabling or disabling actions

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top