mirror of
https://github.com/lemeow125/StudE-Backend.git
synced 2024-11-17 06:19:24 +08:00
Connected course to user
This commit is contained in:
parent
a12e66caed
commit
48f6bee125
6 changed files with 67 additions and 9 deletions
|
@ -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')}),
|
||||
)
|
||||
|
||||
|
||||
|
|
20
stude/accounts/migrations/0002_alter_customuser_course.py
Normal file
20
stude/accounts/migrations/0002_alter_customuser_course.py
Normal file
|
@ -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'),
|
||||
),
|
||||
]
|
20
stude/accounts/migrations/0003_alter_customuser_course.py
Normal file
20
stude/accounts/migrations/0003_alter_customuser_course.py
Normal file
|
@ -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'),
|
||||
),
|
||||
]
|
20
stude/accounts/migrations/0004_alter_customuser_course.py
Normal file
20
stude/accounts/migrations/0004_alter_customuser_course.py
Normal file
|
@ -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'),
|
||||
),
|
||||
]
|
|
@ -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):
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
from django.db import models
|
||||
from accounts.models import CustomUser as User
|
||||
# Create your models here.
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue