I'm using django rest framework and I have a ListAPIView that I would like
to implement a complex filtering functionality that I'm using Q filters. My
question is how do I generate custom fields for this filtering?
url:
path('', EventListView.as_view(), name='event_list_view'),
serializer:
class EventSerializer(serializers.ModelSerializer):
class Meta:
model = Event
exclude = ('user', )
View:
class EventListView(ListAPIView):
authentication_classes = ()
permission_classes = ()
serializer_class = EventSerializer
filter function:
def filter_events(
user: User, sort_by: int = DISTANCE, privacy_levels: [int] = [
EVERYONE], categories: [Category] = None,
start_date: datetime.datetime = DEFAULT_START_DATE, end_date:
datetime.datetime = DEFAULT_END_DATE,
distance: int = DEFAULT_DISTANCE, current_location: Point = None
, unit: int = None,
clubs: [UniversityClub] = None, universities: [University] =
None,
greeks: [GreekOrganization] = None, groups: [UserGroup] = None,
users_p: [User] = None
):
....
if EVERYONE in privacy_levels:
everyone_q = Q(privacy_level=EVERYONE, university__in=
user_universities, start_time__range=[start_date, end_date])
else:
everyone_q = Q()
if STUDENTS in privacy_levels:
student_q = Q(privacy_level=STUDENTS, start_time__range=[
start_date, end_date])
else:
student_q = Q()
...
--
You received this message because you are subscribed to the Google Groups
"Django REST framework" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-rest-framework/f53f029c-ff9e-4b1a-91ae-9e2101ac4c91%40googlegroups.com.