mirror of
https://github.com/lemeow125/StudE-Backend.git
synced 2024-11-17 06:19:24 +08:00
Polished student_status serializer
This commit is contained in:
parent
4b20812021
commit
05d9dbd296
2 changed files with 10 additions and 7 deletions
|
@ -11,6 +11,7 @@ from djangochannelsrestframework.mixins import (
|
|||
ListModelMixin,
|
||||
RetrieveModelMixin,
|
||||
)
|
||||
from djangochannelsrestframework.permissions import IsAuthenticated
|
||||
|
||||
|
||||
class StudentStatusConsumer(
|
||||
|
@ -18,8 +19,8 @@ class StudentStatusConsumer(
|
|||
RetrieveModelMixin,
|
||||
GenericAsyncAPIConsumer,
|
||||
):
|
||||
|
||||
queryset = StudentStatus.objects.all()
|
||||
permission_classes = [IsAuthenticated]
|
||||
queryset = StudentStatus.objects.filter(active=True)
|
||||
serializer_class = StudentStatusSerializer
|
||||
|
||||
async def websocket_connect(self, message):
|
||||
|
@ -41,9 +42,9 @@ class StudentStatusConsumer(
|
|||
while True:
|
||||
try:
|
||||
data = await self.get_student_statuses()
|
||||
print(f"Sending update: {data}") # existing debug statement
|
||||
# print(f"Sending update: {data}") Debug
|
||||
await self.send(text_data=json.dumps(data))
|
||||
await asyncio.sleep(0.5)
|
||||
await asyncio.sleep(5)
|
||||
except Exception as e:
|
||||
print(f"Exception in send_updates: {e}")
|
||||
break # Break the loop on error
|
||||
|
|
|
@ -3,9 +3,11 @@ from .models import StudentStatus
|
|||
|
||||
|
||||
class StudentStatusSerializer(serializers.ModelSerializer):
|
||||
year_level = serializers.CharField(source='user.year_level', read_only=True)
|
||||
year_level = serializers.CharField(
|
||||
source='user.year_level', read_only=True)
|
||||
course = serializers.CharField(source='user.course', read_only=True)
|
||||
semester = serializers.CharField(source='user.semester', read_only=True)
|
||||
user = serializers.CharField(source='user.full_name', read_only=True)
|
||||
|
||||
class Meta:
|
||||
model = StudentStatus
|
||||
|
@ -17,7 +19,7 @@ class StudentStatusSerializer(serializers.ModelSerializer):
|
|||
student_status = StudentStatus.objects.create(
|
||||
user=user, defaults=validated_data)
|
||||
return student_status
|
||||
|
||||
|
||||
def update(self, instance, validated_data):
|
||||
active = validated_data.get('active', None)
|
||||
|
||||
|
@ -26,4 +28,4 @@ class StudentStatusSerializer(serializers.ModelSerializer):
|
|||
validated_data['y'] = None
|
||||
validated_data['subject'] = None
|
||||
|
||||
return super().update(instance, validated_data)
|
||||
return super().update(instance, validated_data)
|
||||
|
|
Loading…
Reference in a new issue