Commit 5325eb00 authored by Julien Palard's avatar Julien Palard
Browse files

Allow to filter answers on username.

parent acceb74e
from django.contrib.auth.models import User, Group
from django_filters import rest_framework as filters
import django_filters
from rest_framework import permissions
from rest_framework import routers
from rest_framework import serializers
......@@ -112,10 +114,18 @@ class GroupViewSet(viewsets.ModelViewSet):
serializer_class = GroupSerializer
class AnswerFilter(filters.FilterSet):
username = django_filters.CharFilter(field_name="user__username")
class Meta:
model = Answer
fields = ("is_corrected", "is_valid", "user")
class AnswerViewSet(viewsets.ModelViewSet):
permission_classes = [AnswerPermission]
queryset = Answer.objects.all()
filterset_fields = ("is_corrected", "is_valid", "user")
filterset_class = AnswerFilter
def get_queryset(self):
if self.request.user.is_staff:
Supports Markdown
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