def dispatch(self, request, *args, **kwargs): search = request.GET.get("search") if not search or len(search) < 2: return JsonResponse({"count": 0, "results": []}) queryset = Member.objects.filter(Member.get_query_for_search(search)) return JsonResponse({ "count": len(queryset), "results": [{ "id": member.pk, "nick": member.profile_profile.nick, "name": member.name, } for member in queryset], })
def get_members_queryset(self, search=None, _filter="active"): qs = Member.objects.all() if search: qs = qs.filter(Member.get_query_for_search(search)) # Logic: # + Active members have membership with start <= today and (end is null or end >= today) active_q = Q(memberships__start__lte=now().date()) & ( Q(memberships__end__isnull=True) | Q(memberships__end__gte=now().date())) inactive_q = ~active_q if _filter == "all": pass elif _filter == "inactive": qs = qs.filter(inactive_q) else: # Default to 'active' qs = qs.filter(active_q) return qs.order_by("-id").distinct()