mirror of
https://github.com/lemeow125/StudE-Backend.git
synced 2024-11-17 06:19:24 +08:00
Add formatted timestamp to student status serializer
This commit is contained in:
parent
cc52931956
commit
4a96774ba8
4 changed files with 25 additions and 8 deletions
|
@ -0,0 +1,18 @@
|
||||||
|
# Generated by Django 4.2.3 on 2023-08-15 10:51
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('student_status', '0002_initial'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name='studentstatus',
|
||||||
|
name='timestamp',
|
||||||
|
field=models.DateTimeField(auto_now_add=True),
|
||||||
|
),
|
||||||
|
]
|
|
@ -13,7 +13,7 @@ class StudentStatus(models.Model):
|
||||||
subject = models.ForeignKey(
|
subject = models.ForeignKey(
|
||||||
'subjects.Subject', on_delete=models.SET_NULL, null=True)
|
'subjects.Subject', on_delete=models.SET_NULL, null=True)
|
||||||
active = models.BooleanField(default=False)
|
active = models.BooleanField(default=False)
|
||||||
timestamp = models.DateField(auto_now_add=True)
|
timestamp = models.DateTimeField(auto_now_add=True)
|
||||||
landmark = models.ForeignKey(
|
landmark = models.ForeignKey(
|
||||||
'landmarks.Landmark', on_delete=models.SET_NULL, null=True)
|
'landmarks.Landmark', on_delete=models.SET_NULL, null=True)
|
||||||
study_group = models.ManyToManyField(
|
study_group = models.ManyToManyField(
|
||||||
|
|
|
@ -13,11 +13,14 @@ class StudentStatusSerializer(serializers.ModelSerializer):
|
||||||
location = PointField(required=True)
|
location = PointField(required=True)
|
||||||
landmark = serializers.SlugRelatedField(
|
landmark = serializers.SlugRelatedField(
|
||||||
queryset=Landmark.objects.all(), many=False, slug_field='name', required=False, allow_null=True)
|
queryset=Landmark.objects.all(), many=False, slug_field='name', required=False, allow_null=True)
|
||||||
|
|
||||||
|
timestamp = serializers.DateTimeField(format="%Y-%m-%d %H:%M:%S")
|
||||||
active = serializers.BooleanField(required=True)
|
active = serializers.BooleanField(required=True)
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
model = StudentStatus
|
model = StudentStatus
|
||||||
fields = ['user', 'subject', 'location', 'active', 'landmark']
|
fields = ['user', 'subject', 'location',
|
||||||
|
'timestamp', 'active', 'landmark']
|
||||||
read_only_fields = ['user', 'landmark']
|
read_only_fields = ['user', 'landmark']
|
||||||
|
|
||||||
def create(self, validated_data):
|
def create(self, validated_data):
|
||||||
|
|
|
@ -9,20 +9,16 @@ class StudentStatusAPIView(generics.RetrieveUpdateAPIView):
|
||||||
serializer_class = StudentStatusSerializer
|
serializer_class = StudentStatusSerializer
|
||||||
permission_classes = [IsAuthenticated]
|
permission_classes = [IsAuthenticated]
|
||||||
|
|
||||||
def get_queryset(self):
|
def get_object(self):
|
||||||
user = self.request.user
|
user = self.request.user
|
||||||
queryset = StudentStatus.objects.filter(user=user)
|
queryset = StudentStatus.objects.filter(user=user)
|
||||||
return queryset
|
|
||||||
|
|
||||||
def get_object(self):
|
|
||||||
queryset = self.get_queryset()
|
|
||||||
obj = get_object_or_404(queryset)
|
obj = get_object_or_404(queryset)
|
||||||
return obj
|
return obj
|
||||||
|
|
||||||
|
|
||||||
class ActiveStudentStatusListAPIView(generics.ListAPIView):
|
class ActiveStudentStatusListAPIView(generics.ListAPIView):
|
||||||
serializer_class = StudentStatusSerializer
|
serializer_class = StudentStatusSerializer
|
||||||
# permission_classes = [IsAuthenticated]
|
permission_classes = [IsAuthenticated]
|
||||||
|
|
||||||
def get_queryset(self):
|
def get_queryset(self):
|
||||||
user = self.request.user
|
user = self.request.user
|
||||||
|
|
Loading…
Reference in a new issue