Commit e12c4425 authored by Fernando Ribeiro's avatar Fernando Ribeiro
Browse files

Feat: Add query in backend for Students in classes

parent 15f7c1a4
......@@ -6,7 +6,7 @@ from rest_framework import viewsets, mixins
from rest_framework.response import Response
from rest_framework.permissions import IsAuthenticated
from .models import (Course, CourseProfessor, ProfessorMessage, ProfessorMessageRead)
from .models import (Course, CourseProfessor, ProfessorMessage, ProfessorMessageRead, Class)
from .serializers import (CourseSerializer, BasicCourseProfessorSerializer,
ProfessorMessageSerializer, ProfessorMessageReadSerializer,
......@@ -98,6 +98,8 @@ class ProfessorMessageViewSet(viewsets.ModelViewSet):
recipients = serializer.context['request'].data.get('users', None)
groups = serializer.context['request'].data.get('groups', None)
classes = serializer.context['request'].data.get('classes', None)
users_to_be_added = []
User = get_user_model()
# If groups were specified, their users are the recipients
......@@ -107,6 +109,11 @@ class ProfessorMessageViewSet(viewsets.ModelViewSet):
elif recipients:
for user_id in serializer.context['request'].data['users']:
elif classes:
for class_id in classes:
klass = Class.objects.get(id=class_id)
for user in klass.students.all():
obj =, users=users_to_be_added)
if obj:
Markdown is supported
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