Z
Z
zkweb2015-10-23 14:51:18
Django
zkweb, 2015-10-23 14:51:18

How to add view right in Django Admin - view?

By default, django admin has three rules: create, edit, delete. How do I add a new view. VIEW

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexey Sorokin, 2015-10-29
@replytoall

If I understand the question correctly, this can be done through groups. You can write like this:

from django.contrib.auth.decorators import user_passes_test

# декоратор для проверки вхождения пользователя request.user в определенную группу
def group_required(*group_names):
    def in_groups(user):
        if user.is_authenticated():
            if user.is_superuser or bool(user.groups.filter(name__in=group_names)):
                return True
        return False
    return user_passes_test(in_groups)

# оборачиваем нужную функцию из views.py в декоратор. Проверяем входит ли пользователь request.user в группу name_of_group
@group_required('name_of_group')
def home(request):
    pass

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question