from rest_framework.viewsets import GenericViewSet
from common.helpers import get_organization_by_user


class AdminFilterMixin:
    admin_param_name = 'admin'

    def get_query(self, queryset):
        request = self.request  # noqa

        if request.query_params.get(self.admin_param_name):
            return queryset.order_by('-create_date')

        return queryset.filter(organization=get_organization_by_user(request.user)).order_by('-create_date')
