diff --git a/stude/accounts/migrations/0001_initial.py b/stude/accounts/migrations/0001_initial.py index 3036706..c3df0a2 100644 --- a/stude/accounts/migrations/0001_initial.py +++ b/stude/accounts/migrations/0001_initial.py @@ -1,9 +1,10 @@ -# Generated by Django 4.2.2 on 2023-06-27 09:44 +# Generated by Django 4.2.2 on 2023-06-27 13:08 import accounts.models import django.contrib.auth.models import django.contrib.auth.validators from django.db import migrations, models +import django.db.models.deletion import django.utils.timezone @@ -12,6 +13,10 @@ class Migration(migrations.Migration): initial = True dependencies = [ + ('auth', '0012_alter_user_first_name_max_length'), + ('courses', '0002_initial'), + ('semesters', '0001_initial'), + ('year_levels', '0001_initial'), ] operations = [ @@ -34,6 +39,11 @@ class Migration(migrations.Migration): ('is_banned', models.BooleanField(default=False)), ('student_id_number', models.CharField(max_length=16, validators=[accounts.models.validate_student_id])), ('avatar', models.ImageField(null=True, upload_to=accounts.models.CustomUser._get_upload_to)), + ('course', models.ForeignKey(null=True, on_delete=django.db.models.deletion.CASCADE, to='courses.course')), + ('groups', models.ManyToManyField(blank=True, help_text='The groups this user belongs to. A user will get all permissions granted to each of their groups.', related_name='user_set', related_query_name='user', to='auth.group', verbose_name='groups')), + ('semester', models.ForeignKey(null=True, on_delete=django.db.models.deletion.CASCADE, to='semesters.semester')), + ('user_permissions', models.ManyToManyField(blank=True, help_text='Specific permissions for this user.', related_name='user_set', related_query_name='user', to='auth.permission', verbose_name='user permissions')), + ('year_level', models.ForeignKey(null=True, on_delete=django.db.models.deletion.CASCADE, to='year_levels.year_level')), ], options={ 'verbose_name': 'user', diff --git a/stude/accounts/migrations/0002_initial.py b/stude/accounts/migrations/0002_initial.py deleted file mode 100644 index 0b53397..0000000 --- a/stude/accounts/migrations/0002_initial.py +++ /dev/null @@ -1,45 +0,0 @@ -# Generated by Django 4.2.2 on 2023-06-27 09:44 - -from django.db import migrations, models -import django.db.models.deletion - - -class Migration(migrations.Migration): - - initial = True - - dependencies = [ - ('auth', '0012_alter_user_first_name_max_length'), - ('year_levels', '0001_initial'), - ('semesters', '0001_initial'), - ('accounts', '0001_initial'), - ('courses', '0002_initial'), - ] - - operations = [ - migrations.AddField( - model_name='customuser', - name='course', - field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.CASCADE, to='courses.course'), - ), - migrations.AddField( - model_name='customuser', - name='groups', - field=models.ManyToManyField(blank=True, help_text='The groups this user belongs to. A user will get all permissions granted to each of their groups.', related_name='user_set', related_query_name='user', to='auth.group', verbose_name='groups'), - ), - migrations.AddField( - model_name='customuser', - name='semester', - field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.CASCADE, to='semesters.semester'), - ), - migrations.AddField( - model_name='customuser', - name='user_permissions', - field=models.ManyToManyField(blank=True, help_text='Specific permissions for this user.', related_name='user_set', related_query_name='user', to='auth.permission', verbose_name='user permissions'), - ), - 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'), - ), - ] diff --git a/stude/accounts/models.py b/stude/accounts/models.py index 839abdf..37c8225 100644 --- a/stude/accounts/models.py +++ b/stude/accounts/models.py @@ -1,15 +1,13 @@ -import time from django.contrib.auth.models import AbstractUser from django.core.exceptions import ValidationError from django.utils.text import slugify from django.db import models -import os from courses.models import Course from year_levels.models import Year_Level from semesters.models import Semester from django.db.models.signals import post_migrate from django.dispatch import receiver -from dotenv import load_dotenv +import os def validate_student_id(value): diff --git a/stude/config/settings.py b/stude/config/settings.py index bfee7f0..2892cbc 100644 --- a/stude/config/settings.py +++ b/stude/config/settings.py @@ -67,6 +67,7 @@ INSTALLED_APPS = [ 'year_levels', 'semesters', 'subjects', + 'study_groups', ] MIDDLEWARE = [ diff --git a/stude/student_status/migrations/0001_initial.py b/stude/student_status/migrations/0001_initial.py index a45be78..24adbf9 100644 --- a/stude/student_status/migrations/0001_initial.py +++ b/stude/student_status/migrations/0001_initial.py @@ -1,4 +1,4 @@ -# Generated by Django 4.2.2 on 2023-06-27 09:44 +# Generated by Django 4.2.2 on 2023-06-27 13:08 from django.conf import settings from django.db import migrations, models diff --git a/stude/student_status/migrations/0002_initial.py b/stude/student_status/migrations/0002_initial.py new file mode 100644 index 0000000..624ece8 --- /dev/null +++ b/stude/student_status/migrations/0002_initial.py @@ -0,0 +1,22 @@ +# Generated by Django 4.2.2 on 2023-06-27 13:08 + +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + initial = True + + dependencies = [ + ('study_groups', '0001_initial'), + ('student_status', '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'), + ), + ] diff --git a/stude/student_status/migrations/0003_alter_studentstatus_subject.py b/stude/student_status/migrations/0003_alter_studentstatus_subject.py new file mode 100644 index 0000000..da0fd9e --- /dev/null +++ b/stude/student_status/migrations/0003_alter_studentstatus_subject.py @@ -0,0 +1,20 @@ +# Generated by Django 4.2.2 on 2023-06-27 13:10 + +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + ('subjects', '0001_initial'), + ('student_status', '0002_initial'), + ] + + operations = [ + migrations.AlterField( + model_name='studentstatus', + name='subject', + field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.CASCADE, to='subjects.subject'), + ), + ] diff --git a/stude/student_status/models.py b/stude/student_status/models.py index 8b24184..2447f83 100644 --- a/stude/student_status/models.py +++ b/stude/student_status/models.py @@ -1,26 +1,18 @@ from django.db import models from accounts.models import CustomUser +from study_groups.models import StudyGroup # Create your models here. class StudentStatus(models.Model): - YEAR_LEVELS = ( - ('1st', '1st year'), - ('2nd', '2nd year'), - ('3rd', '3rd year'), - ('4th', '4th year'), - ('5th', '5th Year'), - ('Irreg', 'Irregular'), - ) - SEMESTERS = ( - ('1st', '1st semester'), - ('2nd', '2nd semester'), - ) user = models.OneToOneField( CustomUser, on_delete=models.CASCADE, primary_key=True) x = models.FloatField(null=True) y = models.FloatField(null=True) - subject = models.CharField(max_length=100, null=True) + subject = models.ForeignKey( + 'subjects.Subject', on_delete=models.CASCADE, null=True) active = models.BooleanField(default=False) timestamp = models.DateField(auto_now_add=True) + study_group = models.ForeignKey( + StudyGroup, on_delete=models.SET_NULL, null=True) diff --git a/stude/study_groups/__init__.py b/stude/study_groups/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/stude/study_groups/admin.py b/stude/study_groups/admin.py new file mode 100644 index 0000000..fcfbcbe --- /dev/null +++ b/stude/study_groups/admin.py @@ -0,0 +1,6 @@ +from django.contrib import admin +from .models import StudyGroup, StudyGroupMembership + + +admin.site.register(StudyGroup) +admin.site.register(StudyGroupMembership) diff --git a/stude/study_groups/apps.py b/stude/study_groups/apps.py new file mode 100644 index 0000000..3a5472d --- /dev/null +++ b/stude/study_groups/apps.py @@ -0,0 +1,6 @@ +from django.apps import AppConfig + + +class StudyGroupsConfig(AppConfig): + default_auto_field = 'django.db.models.BigAutoField' + name = 'study_groups' diff --git a/stude/study_groups/migrations/0001_initial.py b/stude/study_groups/migrations/0001_initial.py new file mode 100644 index 0000000..37b0202 --- /dev/null +++ b/stude/study_groups/migrations/0001_initial.py @@ -0,0 +1,41 @@ +# Generated by Django 4.2.2 on 2023-06-27 13:08 + +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + initial = True + + dependencies = [ + ('student_status', '0001_initial'), + ('subjects', '0001_initial'), + ] + + operations = [ + migrations.CreateModel( + name='StudyGroup', + fields=[ + ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('x', models.FloatField(null=True)), + ('y', models.FloatField(null=True)), + ('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')), + ], + ), + migrations.CreateModel( + name='StudyGroupMembership', + fields=[ + ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('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='student_status.studentstatus')), + ], + ), + migrations.AddField( + model_name='studygroup', + name='users', + field=models.ManyToManyField(through='study_groups.StudyGroupMembership', to='student_status.studentstatus'), + ), + ] diff --git a/stude/study_groups/migrations/__init__.py b/stude/study_groups/migrations/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/stude/study_groups/models.py b/stude/study_groups/models.py new file mode 100644 index 0000000..0e4ef14 --- /dev/null +++ b/stude/study_groups/models.py @@ -0,0 +1,20 @@ +from django.db import models +from subjects.models import Subject +# Create your models here. + + +class StudyGroup(models.Model): + users = models.ManyToManyField( + 'student_status.StudentStatus', through='StudyGroupMembership') + x = models.FloatField(null=True) + y = models.FloatField(null=True) + subject = models.ForeignKey(Subject, on_delete=models.CASCADE) + active = models.BooleanField(default=False) + timestamp = models.DateField(auto_now_add=True) + + +class StudyGroupMembership(models.Model): + user = models.ForeignKey( + 'student_status.StudentStatus', on_delete=models.CASCADE) + study_group = models.ForeignKey( + 'study_groups.StudyGroup', on_delete=models.CASCADE) diff --git a/stude/study_groups/tests.py b/stude/study_groups/tests.py new file mode 100644 index 0000000..7ce503c --- /dev/null +++ b/stude/study_groups/tests.py @@ -0,0 +1,3 @@ +from django.test import TestCase + +# Create your tests here. diff --git a/stude/study_groups/views.py b/stude/study_groups/views.py new file mode 100644 index 0000000..91ea44a --- /dev/null +++ b/stude/study_groups/views.py @@ -0,0 +1,3 @@ +from django.shortcuts import render + +# Create your views here.