Commit d5c9fc5a authored by okhin's avatar okhin

Adding a filter for feedbacks

parent ee2524c0
Pipeline #909 passed with stages
in 47 seconds
from django.contrib import admin
from picampaign.organization.models import FeedbackCategory
from import Feedback
class FeedbackFilterByCategory(admin.SimpleListFilter):
title = 'category'
parameter_name = 'category'
def lookups(self, request, model_admin):
if request.user.is_superuser:
feedbacks = Feedback.objects.all().values_list('category__id', 'category__name')
user_orgs = [ for x in request.user.organizations.all()]
feedbacks = Feedback.objects.filter(category__organisation__in=user_orgs).values_list('category_id', 'category_name')
return ((f[0], f[1],) for f in sorted(set(feedbacks), key=lambda f: f[1]))
def queryset(self, request, queryset):
if self.value():
return queryset.filter(category__id=self.value())
return queryset
class FeedbackAdmin(admin.ModelAdmin):
list_filter = (FeedbackFilterByCategory,)
def get_queryset(self, request):
qs = super(FeedbackAdmin, self).get_queryset(request)
if request.user.is_superuser:
return qs
user_orgs = [ for x in request.user.organizations.all()]
return qs.filter(category__organization__in=user_orgs), FeedbackAdmin)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment