admin.py 1.39 KB
Newer Older
Aymeric Barantal's avatar
Aymeric Barantal committed
1
from django.contrib import admin
2
from picampaign.campaign.models import (Campaign, CampaignContact,
3
                                        Argumentary)
Aymeric Barantal's avatar
Aymeric Barantal committed
4

5 6 7 8 9 10 11 12

class InlineContact(admin.TabularInline):
    model = CampaignContact


class CampaignAdmin(admin.ModelAdmin):
    inlines = [InlineContact]

13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
    def get_queryset(self, request):
        qs = super(CampaignAdmin, 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 CampaignContactAdmin(admin.ModelAdmin):

    def get_queryset(self, request):
        qs = super(CampaignContactAdmin, 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(campaign__organization__in=user_orgs)


class ArgumentaryAdmin(admin.ModelAdmin):

    def get_queryset(self, request):
        qs = super(ArgumentaryAdmin, 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(campaign__organization__in=user_orgs)

40 41

admin.site.register(Campaign, CampaignAdmin)
42 43
admin.site.register(CampaignContact, CampaignContactAdmin)
admin.site.register(Argumentary, ArgumentaryAdmin)