Migrated location fields to new format. Also fixed student_status serializer

This commit is contained in:
Keannu Bernasol 2023-07-09 19:00:47 +08:00
parent 14d99fc7c2
commit 98177f7235
23 changed files with 69 additions and 221 deletions

View file

@ -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
import accounts.models
import django.contrib.auth.models
@ -25,10 +25,10 @@ class Migration(migrations.Migration):
('username', models.CharField(error_messages={'unique': 'A user with that username already exists.'}, help_text='Required. 150 characters or fewer. Letters, digits and @/./+/-/_ only.', max_length=150, unique=True, validators=[django.contrib.auth.validators.UnicodeUsernameValidator()], verbose_name='username')),
('email', models.EmailField(blank=True, max_length=254, verbose_name='email address')),
('is_staff', models.BooleanField(default=False, help_text='Designates whether the user can log into this admin site.', verbose_name='staff status')),
('is_active', models.BooleanField(default=True, help_text='Designates whether this user should be treated as active. Unselect this instead of deleting accounts.', verbose_name='active')),
('date_joined', models.DateTimeField(default=django.utils.timezone.now, verbose_name='date joined')),
('first_name', models.CharField(max_length=100)),
('last_name', models.CharField(max_length=100)),
('is_active', models.BooleanField(default=False)),
('is_student', models.BooleanField(default=True)),
('is_studying', models.BooleanField(default=False)),
('is_banned', models.BooleanField(default=False)),

View file

@ -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
@ -9,18 +9,19 @@ class Migration(migrations.Migration):
initial = True
dependencies = [
('auth', '0012_alter_user_first_name_max_length'),
('year_levels', '0001_initial'),
('accounts', '0001_initial'),
('courses', '0002_initial'),
('accounts', '0001_initial'),
('semesters', '0001_initial'),
('year_levels', '0001_initial'),
('auth', '0012_alter_user_first_name_max_length'),
('subjects', '0001_initial'),
]
operations = [
migrations.AddField(
model_name='customuser',
name='course',
field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.CASCADE, to='courses.course'),
field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, to='courses.course'),
),
migrations.AddField(
model_name='customuser',
@ -30,7 +31,12 @@ class Migration(migrations.Migration):
migrations.AddField(
model_name='customuser',
name='semester',
field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.CASCADE, to='semesters.semester'),
field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, to='semesters.semester'),
),
migrations.AddField(
model_name='customuser',
name='subjects',
field=models.ManyToManyField(related_name='SubjectStudent_user', through='subjects.SubjectStudent', to='subjects.subject'),
),
migrations.AddField(
model_name='customuser',
@ -40,6 +46,6 @@ class Migration(migrations.Migration):
migrations.AddField(
model_name='customuser',
name='year_level',
field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.CASCADE, to='year_levels.year_level'),
field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, to='year_levels.year_level'),
),
]

View file

@ -1,19 +0,0 @@
# Generated by Django 4.2.2 on 2023-06-28 03:09
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('subjects', '0002_subjectstudent_subject_students'),
('accounts', '0002_initial'),
]
operations = [
migrations.AddField(
model_name='customuser',
name='subjects',
field=models.ManyToManyField(related_name='SubjectStudent_user', through='subjects.SubjectStudent', to='subjects.subject'),
),
]

View file

@ -1,32 +0,0 @@
# Generated by Django 4.2.2 on 2023-07-04 10:04
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
('semesters', '0001_initial'),
('courses', '0002_initial'),
('year_levels', '0001_initial'),
('accounts', '0003_customuser_subjects'),
]
operations = [
migrations.AlterField(
model_name='customuser',
name='course',
field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, to='courses.course'),
),
migrations.AlterField(
model_name='customuser',
name='semester',
field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, to='semesters.semester'),
),
migrations.AlterField(
model_name='customuser',
name='year_level',
field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, to='year_levels.year_level'),
),
]

View file

@ -1,18 +0,0 @@
# Generated by Django 4.2.2 on 2023-07-04 11:33
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('accounts', '0004_alter_customuser_course_alter_customuser_semester_and_more'),
]
operations = [
migrations.AlterField(
model_name='customuser',
name='is_active',
field=models.BooleanField(default=False),
),
]

View file

@ -11,6 +11,7 @@ from django.contrib.auth.password_validation import validate_password
from courses.models import Course
from year_levels.models import Year_Level
from semesters.models import Semester
from django.contrib.gis.geos import Point
class CustomUserSerializer(BaseUserSerializer):
@ -35,7 +36,8 @@ class CustomUserSerializer(BaseUserSerializer):
class UserRegistrationSerializer(serializers.ModelSerializer):
email = serializers.EmailField(required=True)
student_id_number = serializers.CharField(required=True)
password = serializers.CharField(write_only=True)
password = serializers.CharField(
write_only=True, style={'input_type': 'password', 'placeholder': 'Password'})
class Meta:
model = CustomUser # Use your custom user model here
@ -64,8 +66,7 @@ class UserRegistrationSerializer(serializers.ModelSerializer):
StudentStatus.objects.create(
user=user,
active=False,
x=None,
y=None,
location=Point(0, 0),
subject=None
)
return user

View file

@ -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

View file

@ -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
@ -9,8 +9,8 @@ class Migration(migrations.Migration):
initial = True
dependencies = [
('subjects', '0001_initial'),
('courses', '0001_initial'),
('subjects', '0001_initial'),
]
operations = [

View file

@ -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

View file

@ -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)),
],

View file

@ -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'),
),
]

View file

@ -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'),
),
]

View file

@ -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'),
),
]

View file

@ -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'),
),
]

View file

@ -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)

View file

@ -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)

View file

@ -1,5 +1,6 @@
# Generated by Django 4.2.2 on 2023-06-27 15:21
# Generated by Django 4.2.3 on 2023-07-09 10:57
import django.contrib.gis.db.models.fields
from django.db import migrations, models
import django.db.models.deletion
@ -19,8 +20,7 @@ class Migration(migrations.Migration):
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('name', models.CharField(max_length=48)),
('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)),
('subject', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='subjects.subject')),

View file

@ -1,5 +1,7 @@
from django.db import models
from subjects.models import Subject
from django.contrib.gis.db import models as gis_models
from django.contrib.gis.geos import Point
# Create your models here.
@ -7,8 +9,7 @@ class StudyGroup(models.Model):
name = models.CharField(max_length=48)
users = models.ManyToManyField(
'student_status.StudentStatus', through='StudyGroupMembership')
x = models.FloatField(null=True)
y = models.FloatField(null=True)
location = gis_models.PointField(blank=True, null=True)
subject = models.ForeignKey(Subject, on_delete=models.CASCADE)
active = models.BooleanField(default=False)
timestamp = models.DateField(auto_now_add=True)

View file

@ -1,4 +1,4 @@
# Generated by Django 4.2.2 on 2023-06-27 15:24
# Generated by Django 4.2.3 on 2023-07-09 10:57
from django.conf import settings
from django.db import migrations, models
@ -20,7 +20,7 @@ class Migration(migrations.Migration):
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('message_content', models.TextField(max_length=1024)),
('timestamp', models.DateField(auto_now_add=True)),
('timestamp', models.DateTimeField(auto_now_add=True)),
('study_group', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='study_groups.studygroup')),
('user', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)),
],

View file

@ -1,18 +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 = [
('studygroup_messages', '0001_initial'),
]
operations = [
migrations.AlterField(
model_name='message',
name='timestamp',
field=models.DateTimeField(auto_now_add=True),
),
]

View file

@ -1,5 +1,6 @@
# 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
from django.db import migrations, models
import django.db.models.deletion
@ -9,9 +10,10 @@ class Migration(migrations.Migration):
initial = True
dependencies = [
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
('semesters', '0001_initial'),
('year_levels', '0001_initial'),
('courses', '0001_initial'),
('year_levels', '0001_initial'),
]
operations = [
@ -23,7 +25,24 @@ class Migration(migrations.Migration):
('code', models.CharField(max_length=16)),
('courses', models.ManyToManyField(related_name='SubjectCourse_subject', through='courses.SubjectCourse', to='courses.course')),
('semester', models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, to='semesters.semester')),
('year_level', models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='Year_Level_name', to='year_levels.year_level')),
],
),
migrations.CreateModel(
name='SubjectStudent',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('subject', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='subjects.subject')),
('user', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)),
],
),
migrations.AddField(
model_name='subject',
name='students',
field=models.ManyToManyField(related_name='SubjectStudent_subject', through='subjects.SubjectStudent', to=settings.AUTH_USER_MODEL),
),
migrations.AddField(
model_name='subject',
name='year_level',
field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='Year_Level_name', to='year_levels.year_level'),
),
]

View file

@ -1,29 +0,0 @@
# Generated by Django 4.2.2 on 2023-06-28 03:09
from django.conf import settings
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
('subjects', '0001_initial'),
]
operations = [
migrations.CreateModel(
name='SubjectStudent',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('subject', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='subjects.subject')),
('user', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)),
],
),
migrations.AddField(
model_name='subject',
name='students',
field=models.ManyToManyField(related_name='SubjectStudent_subject', through='subjects.SubjectStudent', to=settings.AUTH_USER_MODEL),
),
]

View file

@ -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