mirror of
https://github.com/lemeow125/StudE-Backend.git
synced 2024-11-17 06:19:24 +08:00
Improved student status serializer
This commit is contained in:
parent
e79671b9b9
commit
3df8aed143
2 changed files with 11 additions and 0 deletions
|
@ -26,9 +26,14 @@ class StudentStatusSerializer(serializers.ModelSerializer):
|
||||||
return student_status
|
return student_status
|
||||||
|
|
||||||
def update(self, instance, validated_data):
|
def update(self, instance, validated_data):
|
||||||
|
|
||||||
active = validated_data.get('active', None)
|
active = validated_data.get('active', None)
|
||||||
subject = validated_data.get('subject', None)
|
subject = validated_data.get('subject', None)
|
||||||
|
|
||||||
|
# Do not update if instance if active is not specified
|
||||||
|
if active is None:
|
||||||
|
return instance
|
||||||
|
|
||||||
# If status is set as inactive or if no subject is specified in the request, clear the student status
|
# If status is set as inactive or if no subject is specified in the request, clear the student status
|
||||||
if active is not None and active is False or not subject:
|
if active is not None and active is False or not subject:
|
||||||
validated_data['location'] = Point(0, 0)
|
validated_data['location'] = Point(0, 0)
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
from django.shortcuts import get_object_or_404
|
||||||
from rest_framework import generics, viewsets
|
from rest_framework import generics, viewsets
|
||||||
from rest_framework.permissions import IsAuthenticated
|
from rest_framework.permissions import IsAuthenticated
|
||||||
from .models import StudentStatus
|
from .models import StudentStatus
|
||||||
|
@ -13,6 +14,11 @@ class StudentStatusAPIView(generics.RetrieveUpdateAPIView):
|
||||||
queryset = StudentStatus.objects.filter(user=user)
|
queryset = StudentStatus.objects.filter(user=user)
|
||||||
return queryset
|
return queryset
|
||||||
|
|
||||||
|
def get_object(self):
|
||||||
|
queryset = self.get_queryset()
|
||||||
|
obj = get_object_or_404(queryset)
|
||||||
|
return obj
|
||||||
|
|
||||||
|
|
||||||
class ActiveStudentStatusListAPIView(generics.ListAPIView):
|
class ActiveStudentStatusListAPIView(generics.ListAPIView):
|
||||||
serializer_class = StudentStatusSerializer
|
serializer_class = StudentStatusSerializer
|
||||||
|
|
Loading…
Reference in a new issue