admin.py 1.61 KB
Newer Older
Aymeric Barantal's avatar
Aymeric Barantal committed
1
from django.contrib import admin
2
from picampaign.organization.models import (Organization, Group, GroupType,
3
                                            FeedbackCategory)
Aymeric Barantal's avatar
Aymeric Barantal committed
4

5 6 7 8 9 10 11 12 13 14

class OrganizationAdmin(admin.ModelAdmin):
    def get_queryset(self, request):
        qs = super(OrganizationAdmin, self).get_queryset(request)
        if request.user.is_superuser:
            return qs
        user_orgs = [x.id for x in request.user.organizations.all()]
        return qs.filter(id__in=user_orgs)


15 16 17 18 19 20 21 22 23 24
class GroupTypeAdmin(admin.ModelAdmin):

    def get_queryset(self, request):
        qs = super(GroupTypeAdmin, self).get_queryset(request)
        if request.user.is_superuser:
            return qs
        user_orgs = [x.id for x in request.user.organizations.all()]
        return qs.filter(organization__in=user_orgs)


25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
class GroupAdmin(admin.ModelAdmin):
    def get_queryset(self, request):
        qs = super(GroupAdmin, self).get_queryset(request)
        if request.user.is_superuser:
            return qs
        user_orgs = [x.id for x in request.user.organizations.all()]
        return qs.filter(organization__in=user_orgs)


class CategoryAdmin(admin.ModelAdmin):
    def get_queryset(self, request):
        qs = super(CategoryAdmin, self).get_queryset(request)
        if request.user.is_superuser:
            return qs
        user_orgs = [x.id for x in request.user.organizations.all()]
        return qs.filter(organization__in=user_orgs)


admin.site.register(Organization, OrganizationAdmin)
44
admin.site.register(GroupType, GroupTypeAdmin)
45 46
admin.site.register(Group, GroupAdmin)
admin.site.register(FeedbackCategory, CategoryAdmin)