Hotfix for registration crashing due to non-unique StudentStatus instance creation

This commit is contained in:
Keannu Bernasol 2023-10-02 00:46:44 +08:00
parent 1eb1f71232
commit d7f88e1770
16 changed files with 27 additions and 102 deletions

View file

@ -1,4 +1,4 @@
# Generated by Django 4.2.3 on 2023-09-25 13:07
# Generated by Django 4.2.5 on 2023-10-01 16:37
import accounts.models
import django.contrib.auth.models
@ -13,9 +13,9 @@ class Migration(migrations.Migration):
initial = True
dependencies = [
('courses', '0001_initial'),
('semesters', '0001_initial'),
('auth', '0012_alter_user_first_name_max_length'),
('courses', '0001_initial'),
]
operations = [

View file

@ -1,4 +1,4 @@
# Generated by Django 4.2.3 on 2023-09-25 13:07
# Generated by Django 4.2.5 on 2023-10-01 16:37
from django.db import migrations, models
import django.db.models.deletion
@ -9,9 +9,9 @@ class Migration(migrations.Migration):
initial = True
dependencies = [
('accounts', '0001_initial'),
('year_levels', '0001_initial'),
('subjects', '0001_initial'),
('accounts', '0001_initial'),
('auth', '0012_alter_user_first_name_max_length'),
]

View file

@ -1,21 +0,0 @@
# Generated by Django 4.2.3 on 2023-09-30 15:35
from django.db import migrations
class Migration(migrations.Migration):
dependencies = [
('accounts', '0002_initial'),
]
operations = [
migrations.AlterModelOptions(
name='customuser',
options={},
),
migrations.AlterUniqueTogether(
name='customuser',
unique_together={('first_name', 'last_name')},
),
]

View file

@ -1,21 +0,0 @@
# Generated by Django 4.2.3 on 2023-10-01 05:25
from django.db import migrations
class Migration(migrations.Migration):
dependencies = [
('accounts', '0003_alter_customuser_options_and_more'),
]
operations = [
migrations.AlterModelOptions(
name='customuser',
options={'verbose_name': 'user', 'verbose_name_plural': 'users'},
),
migrations.AlterUniqueTogether(
name='customuser',
unique_together=set(),
),
]

View file

@ -155,10 +155,12 @@ class UserRegistrationSerializer(serializers.ModelSerializer):
user.set_password(validated_data['password'])
user.save()
StudentStatus.objects.create(
StudentStatus.objects.update_or_create(
user=user,
active=False,
location=Point(0, 0),
subject=None
defaults={
'active': False,
'location': Point(0, 0),
'subject': None
}
)
return user

View file

@ -1,4 +1,4 @@
# Generated by Django 4.2.3 on 2023-09-25 13:07
# Generated by Django 4.2.5 on 2023-10-01 16:37
from django.db import migrations, models

View file

@ -1,4 +1,4 @@
# Generated by Django 4.2.3 on 2023-09-25 13:07
# Generated by Django 4.2.5 on 2023-10-01 16:37
import django.contrib.gis.db.models.fields
from django.db import migrations, models

View file

@ -1,4 +1,4 @@
# Generated by Django 4.2.3 on 2023-09-25 13:07
# Generated by Django 4.2.5 on 2023-10-01 16:37
from django.db import migrations, models

View file

@ -1,4 +1,4 @@
# Generated by Django 4.2.3 on 2023-09-25 13:07
# Generated by Django 4.2.5 on 2023-10-01 16:37
from django.conf import settings
import django.contrib.gis.db.models.fields
@ -11,23 +11,24 @@ class Migration(migrations.Migration):
initial = True
dependencies = [
('accounts', '0001_initial'),
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
('study_groups', '0001_initial'),
('landmarks', '0001_initial'),
('subjects', '0001_initial'),
('landmarks', '0001_initial'),
]
operations = [
migrations.CreateModel(
name='StudentStatus',
fields=[
('user', models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, primary_key=True, serialize=False, to=settings.AUTH_USER_MODEL)),
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('location', django.contrib.gis.db.models.fields.PointField(blank=True, null=True, srid=4326)),
('active', models.BooleanField(default=False)),
('timestamp', models.DateTimeField(auto_now_add=True)),
('landmark', models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, to='landmarks.landmark')),
('study_group', models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='students', to='study_groups.studygroup')),
('subject', models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, to='subjects.subject', to_field='name')),
('user', models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)),
],
),
]

View file

@ -8,7 +8,7 @@ from django.dispatch import receiver
class StudentStatus(models.Model):
user = models.OneToOneField(
CustomUser, on_delete=models.CASCADE, primary_key=True)
CustomUser, on_delete=models.CASCADE, unique=True)
location = gis_models.PointField(blank=True, null=True, srid=4326)
subject = models.ForeignKey(
'subjects.Subject', on_delete=models.SET_NULL, null=True, to_field='name')

View file

@ -1,4 +1,4 @@
# Generated by Django 4.2.3 on 2023-09-25 13:07
# Generated by Django 4.2.5 on 2023-10-01 16:37
import django.contrib.gis.db.models.fields
from django.db import migrations, models
@ -19,9 +19,8 @@ class Migration(migrations.Migration):
name='StudyGroup',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('name', models.CharField(max_length=48)),
('name', models.CharField(max_length=48, unique=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)),
('landmark', models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, to='landmarks.landmark')),
('subject', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='subjects.subject')),

View file

@ -1,17 +0,0 @@
# Generated by Django 4.2.5 on 2023-09-26 12:30
from django.db import migrations
class Migration(migrations.Migration):
dependencies = [
('study_groups', '0001_initial'),
]
operations = [
migrations.RemoveField(
model_name='studygroup',
name='active',
),
]

View file

@ -1,18 +0,0 @@
# Generated by Django 4.2.5 on 2023-09-28 12:25
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('study_groups', '0002_remove_studygroup_active'),
]
operations = [
migrations.AlterField(
model_name='studygroup',
name='name',
field=models.CharField(max_length=48, unique=True),
),
]

View file

@ -1,4 +1,4 @@
# Generated by Django 4.2.3 on 2023-09-25 13:07
# Generated by Django 4.2.5 on 2023-10-01 16:37
from django.conf import settings
from django.db import migrations, models
@ -10,8 +10,8 @@ class Migration(migrations.Migration):
initial = True
dependencies = [
('study_groups', '0001_initial'),
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
('study_groups', '0001_initial'),
]
operations = [

View file

@ -1,4 +1,4 @@
# Generated by Django 4.2.3 on 2023-09-25 13:07
# Generated by Django 4.2.5 on 2023-10-01 16:37
from django.conf import settings
from django.db import migrations, models
@ -10,10 +10,10 @@ class Migration(migrations.Migration):
initial = True
dependencies = [
('courses', '0001_initial'),
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
('year_levels', '0001_initial'),
('semesters', '0001_initial'),
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
('courses', '0001_initial'),
]
operations = [

View file

@ -1,4 +1,4 @@
# Generated by Django 4.2.3 on 2023-09-25 13:07
# Generated by Django 4.2.5 on 2023-10-01 16:37
from django.db import migrations, models