diff --git a/stude/student_status/migrations/0003_alter_studentstatus_timestamp.py b/stude/student_status/migrations/0003_alter_studentstatus_timestamp.py new file mode 100644 index 0000000..0a7fea7 --- /dev/null +++ b/stude/student_status/migrations/0003_alter_studentstatus_timestamp.py @@ -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), + ), + ] diff --git a/stude/student_status/models.py b/stude/student_status/models.py index b943154..bd4e1e7 100644 --- a/stude/student_status/models.py +++ b/stude/student_status/models.py @@ -13,7 +13,7 @@ class StudentStatus(models.Model): subject = models.ForeignKey( 'subjects.Subject', on_delete=models.SET_NULL, null=True) active = models.BooleanField(default=False) - timestamp = models.DateField(auto_now_add=True) + timestamp = models.DateTimeField(auto_now_add=True) landmark = models.ForeignKey( 'landmarks.Landmark', on_delete=models.SET_NULL, null=True) study_group = models.ManyToManyField( diff --git a/stude/student_status/serializers.py b/stude/student_status/serializers.py index ebf54ab..1b60814 100644 --- a/stude/student_status/serializers.py +++ b/stude/student_status/serializers.py @@ -13,11 +13,14 @@ class StudentStatusSerializer(serializers.ModelSerializer): location = PointField(required=True) landmark = serializers.SlugRelatedField( 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) class Meta: model = StudentStatus - fields = ['user', 'subject', 'location', 'active', 'landmark'] + fields = ['user', 'subject', 'location', + 'timestamp', 'active', 'landmark'] read_only_fields = ['user', 'landmark'] def create(self, validated_data): diff --git a/stude/student_status/views.py b/stude/student_status/views.py index 96d36f7..06706b6 100644 --- a/stude/student_status/views.py +++ b/stude/student_status/views.py @@ -9,20 +9,16 @@ class StudentStatusAPIView(generics.RetrieveUpdateAPIView): serializer_class = StudentStatusSerializer permission_classes = [IsAuthenticated] - def get_queryset(self): + def get_object(self): user = self.request.user queryset = StudentStatus.objects.filter(user=user) - return queryset - - def get_object(self): - queryset = self.get_queryset() obj = get_object_or_404(queryset) return obj class ActiveStudentStatusListAPIView(generics.ListAPIView): serializer_class = StudentStatusSerializer - # permission_classes = [IsAuthenticated] + permission_classes = [IsAuthenticated] def get_queryset(self): user = self.request.user