mirror of
https://github.com/lemeow125/StudE-Backend.git
synced 2025-06-28 16:25:44 +08:00
Migrated location fields to new format. Also fixed student_status serializer
This commit is contained in:
parent
14d99fc7c2
commit
98177f7235
23 changed files with 69 additions and 221 deletions
|
@ -1,6 +1,7 @@
|
|||
# Generated by Django 4.2.2 on 2023-06-27 15:21
|
||||
# Generated by Django 4.2.3 on 2023-07-09 10:57
|
||||
|
||||
from django.conf import settings
|
||||
import django.contrib.gis.db.models.fields
|
||||
from django.db import migrations, models
|
||||
import django.db.models.deletion
|
||||
|
||||
|
@ -18,8 +19,7 @@ class Migration(migrations.Migration):
|
|||
name='StudentStatus',
|
||||
fields=[
|
||||
('user', models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, primary_key=True, serialize=False, to=settings.AUTH_USER_MODEL)),
|
||||
('x', models.FloatField(null=True)),
|
||||
('y', models.FloatField(null=True)),
|
||||
('location', django.contrib.gis.db.models.fields.PointField(blank=True, null=True, srid=4326)),
|
||||
('active', models.BooleanField(default=False)),
|
||||
('timestamp', models.DateField(auto_now_add=True)),
|
||||
],
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
# Generated by Django 4.2.2 on 2023-06-27 15:21
|
||||
# Generated by Django 4.2.3 on 2023-07-09 10:57
|
||||
|
||||
from django.db import migrations, models
|
||||
import django.db.models.deletion
|
||||
|
@ -10,19 +10,19 @@ class Migration(migrations.Migration):
|
|||
|
||||
dependencies = [
|
||||
('student_status', '0001_initial'),
|
||||
('subjects', '0001_initial'),
|
||||
('study_groups', '0001_initial'),
|
||||
('subjects', '0001_initial'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name='studentstatus',
|
||||
name='study_group',
|
||||
field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, to='study_groups.studygroup'),
|
||||
field=models.ManyToManyField(blank=True, through='study_groups.StudyGroupMembership', to='study_groups.studygroup'),
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='studentstatus',
|
||||
name='subject',
|
||||
field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.CASCADE, to='subjects.subject'),
|
||||
field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, to='subjects.subject'),
|
||||
),
|
||||
]
|
||||
|
|
|
@ -1,23 +0,0 @@
|
|||
# Generated by Django 4.2.2 on 2023-06-27 15:53
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('study_groups', '0001_initial'),
|
||||
('student_status', '0002_initial'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.RemoveField(
|
||||
model_name='studentstatus',
|
||||
name='study_group',
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='studentstatus',
|
||||
name='study_group',
|
||||
field=models.ManyToManyField(blank=True, null=True, through='study_groups.StudyGroupMembership', to='study_groups.studygroup'),
|
||||
),
|
||||
]
|
|
@ -1,19 +0,0 @@
|
|||
# Generated by Django 4.2.2 on 2023-06-27 17:15
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('study_groups', '0001_initial'),
|
||||
('student_status', '0003_remove_studentstatus_study_group_and_more'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterField(
|
||||
model_name='studentstatus',
|
||||
name='study_group',
|
||||
field=models.ManyToManyField(blank=True, through='study_groups.StudyGroupMembership', to='study_groups.studygroup'),
|
||||
),
|
||||
]
|
|
@ -1,20 +0,0 @@
|
|||
# Generated by Django 4.2.2 on 2023-07-04 10:01
|
||||
|
||||
from django.db import migrations, models
|
||||
import django.db.models.deletion
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('subjects', '0002_subjectstudent_subject_students'),
|
||||
('student_status', '0004_alter_studentstatus_study_group'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterField(
|
||||
model_name='studentstatus',
|
||||
name='subject',
|
||||
field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, to='subjects.subject'),
|
||||
),
|
||||
]
|
|
@ -1,15 +1,15 @@
|
|||
from django.db import models
|
||||
from accounts.models import CustomUser
|
||||
from study_groups.models import StudyGroup
|
||||
|
||||
from django.contrib.gis.db import models as gis_models
|
||||
from django.contrib.gis.geos import Point
|
||||
# Create your models here.
|
||||
|
||||
|
||||
class StudentStatus(models.Model):
|
||||
user = models.OneToOneField(
|
||||
CustomUser, on_delete=models.CASCADE, primary_key=True)
|
||||
x = models.FloatField(null=True)
|
||||
y = models.FloatField(null=True)
|
||||
location = gis_models.PointField(blank=True, null=True)
|
||||
subject = models.ForeignKey(
|
||||
'subjects.Subject', on_delete=models.SET_NULL, null=True)
|
||||
active = models.BooleanField(default=False)
|
||||
|
|
|
@ -1,12 +1,12 @@
|
|||
from rest_framework import serializers
|
||||
from .models import StudentStatus
|
||||
from subjects.models import Subject
|
||||
from django.contrib.gis.geos import Point
|
||||
|
||||
|
||||
class StudentStatusSerializer(serializers.ModelSerializer):
|
||||
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)
|
||||
subject = serializers.SlugRelatedField(
|
||||
queryset=Subject.objects.all(), slug_field='name', required=True)
|
||||
user = serializers.CharField(source='user.full_name', read_only=True)
|
||||
|
||||
class Meta:
|
||||
|
@ -24,8 +24,7 @@ class StudentStatusSerializer(serializers.ModelSerializer):
|
|||
active = validated_data.get('active', None)
|
||||
|
||||
if active is not None and active is False:
|
||||
validated_data['x'] = None
|
||||
validated_data['y'] = None
|
||||
validated_data['location'] = Point(0, 0)
|
||||
validated_data['subject'] = None
|
||||
|
||||
return super().update(instance, validated_data)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue