src/notes/api/filters.py
author ymh <ymh.work@gmail.com>
Fri, 30 Nov 2018 10:53:15 +0100
changeset 183 f8f3af9e5c83
parent 128 34a75bd8d0b9
permissions -rw-r--r--
Change the settings to avoid using Session authentication for rest framework as it raise exceptions in case client and backend are on the same domain On the filter, adapt to take into account new version of django_filters

'''
Inspired by https://stackoverflow.com/a/36289332
'''
from django_filters.rest_framework import (BaseInFilter, Filter, FilterSet,
                                           UUIDFilter)

from ..models import Note, Session

class ExtIdFilter(BaseInFilter, UUIDFilter):
    pass

class CoreFilterSet(FilterSet):
    ext_id__in = ExtIdFilter(field_name='ext_id')

class SessionFilterSet(CoreFilterSet):
    class Meta:
        model = Session
        fields = ['ext_id__in']

class NoteFilterSet(CoreFilterSet):
    class Meta:
        model = Note
        fields = ['ext_id__in']