From 48f6bee12533a182f804ed417c1c56c48dee7b93 Mon Sep 17 00:00:00 2001 From: Keannu Bernasol Date: Tue, 27 Jun 2023 14:38:07 +0800 Subject: [PATCH] Connected course to user --- stude/accounts/admin.py | 2 +- .../0002_alter_customuser_course.py | 20 +++++++++++++++++++ .../0003_alter_customuser_course.py | 20 +++++++++++++++++++ .../0004_alter_customuser_course.py | 20 +++++++++++++++++++ stude/accounts/models.py | 13 ++++++------ stude/courses/models.py | 1 - 6 files changed, 67 insertions(+), 9 deletions(-) create mode 100644 stude/accounts/migrations/0002_alter_customuser_course.py create mode 100644 stude/accounts/migrations/0003_alter_customuser_course.py create mode 100644 stude/accounts/migrations/0004_alter_customuser_course.py diff --git a/stude/accounts/admin.py b/stude/accounts/admin.py index 80e6f3c..b071683 100644 --- a/stude/accounts/admin.py +++ b/stude/accounts/admin.py @@ -8,7 +8,7 @@ class CustomUserAdmin(UserAdmin): fieldsets = UserAdmin.fieldsets + ( (None, {'fields': ('student_id_number', - 'year_level', 'semester', 'avatar', 'is_student', 'is_banned')}), + 'year_level', 'semester', 'course', 'avatar', 'is_student', 'is_banned')}), ) diff --git a/stude/accounts/migrations/0002_alter_customuser_course.py b/stude/accounts/migrations/0002_alter_customuser_course.py new file mode 100644 index 0000000..107f8aa --- /dev/null +++ b/stude/accounts/migrations/0002_alter_customuser_course.py @@ -0,0 +1,20 @@ +# Generated by Django 4.2.2 on 2023-06-27 06:29 + +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + ('courses', '0001_initial'), + ('accounts', '0001_initial'), + ] + + operations = [ + migrations.AlterField( + model_name='customuser', + name='course', + field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='courses.course'), + ), + ] diff --git a/stude/accounts/migrations/0003_alter_customuser_course.py b/stude/accounts/migrations/0003_alter_customuser_course.py new file mode 100644 index 0000000..377f458 --- /dev/null +++ b/stude/accounts/migrations/0003_alter_customuser_course.py @@ -0,0 +1,20 @@ +# Generated by Django 4.2.2 on 2023-06-27 06:31 + +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + ('courses', '0001_initial'), + ('accounts', '0002_alter_customuser_course'), + ] + + operations = [ + migrations.AlterField( + model_name='customuser', + name='course', + field=models.ForeignKey(default='BSIT', on_delete=django.db.models.deletion.CASCADE, to='courses.course'), + ), + ] diff --git a/stude/accounts/migrations/0004_alter_customuser_course.py b/stude/accounts/migrations/0004_alter_customuser_course.py new file mode 100644 index 0000000..b19ea6d --- /dev/null +++ b/stude/accounts/migrations/0004_alter_customuser_course.py @@ -0,0 +1,20 @@ +# Generated by Django 4.2.2 on 2023-06-27 06:34 + +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + ('courses', '0001_initial'), + ('accounts', '0003_alter_customuser_course'), + ] + + operations = [ + migrations.AlterField( + model_name='customuser', + name='course', + field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.CASCADE, to='courses.course'), + ), + ] diff --git a/stude/accounts/models.py b/stude/accounts/models.py index a06cb15..9d8fdf8 100644 --- a/stude/accounts/models.py +++ b/stude/accounts/models.py @@ -4,6 +4,7 @@ from django.core.exceptions import ValidationError from django.utils.text import slugify from django.db import models import os +from courses.models import Course def validate_student_id(value): @@ -26,11 +27,6 @@ class CustomUser(AbstractUser): ('1st', '1st semester'), ('2nd', '2nd semester'), ) - COURSES = ( - ('BSIT', 'Bachelor of Science in Information Technology'), - ('BSCS', 'Bachelor of Science in Computer Science'), - ('BSCpE', 'Bachelor of Science in Computer Engineering'), - ) def _get_upload_to(instance, filename): base_filename, file_extension = os.path.splitext(filename) @@ -56,9 +52,12 @@ class CustomUser(AbstractUser): max_length=50, choices=YEAR_LEVELS) semester = models.CharField( max_length=50, choices=SEMESTERS) - course = models.CharField( - max_length=50, choices=COURSES) avatar = models.ImageField(upload_to=_get_upload_to, null=True) + course = models.ForeignKey( + Course, + on_delete=models.CASCADE, + null=True + ) @property def full_name(self): diff --git a/stude/courses/models.py b/stude/courses/models.py index 4719c9e..6f49b09 100644 --- a/stude/courses/models.py +++ b/stude/courses/models.py @@ -1,5 +1,4 @@ from django.db import models -from accounts.models import CustomUser as User # Create your models here.