mirror of
https://github.com/lemeow125/StudE-Backend.git
synced 2024-11-17 06:19:24 +08:00
Further polishing for subjects
This commit is contained in:
parent
de1dabf53c
commit
492a605557
28 changed files with 225 additions and 151 deletions
|
@ -1,4 +1,4 @@
|
|||
# Generated by Django 4.2.2 on 2023-06-27 05:15
|
||||
# Generated by Django 4.2.2 on 2023-06-27 09:44
|
||||
|
||||
import accounts.models
|
||||
import django.contrib.auth.models
|
||||
|
@ -12,7 +12,6 @@ class Migration(migrations.Migration):
|
|||
initial = True
|
||||
|
||||
dependencies = [
|
||||
('auth', '0012_alter_user_first_name_max_length'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
|
@ -34,12 +33,7 @@ class Migration(migrations.Migration):
|
|||
('is_studying', models.BooleanField(default=False)),
|
||||
('is_banned', models.BooleanField(default=False)),
|
||||
('student_id_number', models.CharField(max_length=16, validators=[accounts.models.validate_student_id])),
|
||||
('year_level', models.CharField(choices=[('1st', '1st year'), ('2nd', '2nd year'), ('3rd', '3rd year'), ('4th', '4th year'), ('5th', '5th Year'), ('Irreg', 'Irregular')], max_length=50)),
|
||||
('semester', models.CharField(choices=[('1st', '1st semester'), ('2nd', '2nd semester')], max_length=50)),
|
||||
('course', models.CharField(choices=[('BSIT', 'Bachelor of Science in Information Technology'), ('BSCS', 'Bachelor of Science in Computer Science'), ('BSCpE', 'Bachelor of Science in Computer Engineering')], max_length=50)),
|
||||
('avatar', models.ImageField(null=True, upload_to=accounts.models.CustomUser._get_upload_to)),
|
||||
('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')),
|
||||
('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')),
|
||||
],
|
||||
options={
|
||||
'verbose_name': 'user',
|
||||
|
|
|
@ -1,20 +0,0 @@
|
|||
# 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'),
|
||||
),
|
||||
]
|
45
stude/accounts/migrations/0002_initial.py
Normal file
45
stude/accounts/migrations/0002_initial.py
Normal file
|
@ -0,0 +1,45 @@
|
|||
# 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'),
|
||||
),
|
||||
]
|
|
@ -1,20 +0,0 @@
|
|||
# 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'),
|
||||
),
|
||||
]
|
|
@ -1,20 +0,0 @@
|
|||
# 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'),
|
||||
),
|
||||
]
|
|
@ -1,20 +0,0 @@
|
|||
# Generated by Django 4.2.2 on 2023-06-27 07:29
|
||||
|
||||
from django.db import migrations, models
|
||||
import django.db.models.deletion
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('year_levels', '0001_initial'),
|
||||
('accounts', '0004_alter_customuser_course'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterField(
|
||||
model_name='customuser',
|
||||
name='semester',
|
||||
field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.CASCADE, to='year_levels.year_level'),
|
||||
),
|
||||
]
|
|
@ -1,26 +0,0 @@
|
|||
# Generated by Django 4.2.2 on 2023-06-27 07:45
|
||||
|
||||
from django.db import migrations, models
|
||||
import django.db.models.deletion
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('year_levels', '0001_initial'),
|
||||
('semesters', '0001_initial'),
|
||||
('accounts', '0005_alter_customuser_semester'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterField(
|
||||
model_name='customuser',
|
||||
name='semester',
|
||||
field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.CASCADE, to='semesters.semester'),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='customuser',
|
||||
name='year_level',
|
||||
field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.CASCADE, to='year_levels.year_level'),
|
||||
),
|
||||
]
|
|
@ -6,5 +6,6 @@ urlpatterns = [
|
|||
path('student_status/', include('student_status.urls')),
|
||||
path('courses/', include('courses.urls')),
|
||||
path('year_levels/', include('year_levels.urls')),
|
||||
path('semesters/', include('semesters.urls'))
|
||||
path('semesters/', include('semesters.urls')),
|
||||
path('subjects/', include('subjects.urls'))
|
||||
]
|
||||
|
|
|
@ -66,6 +66,7 @@ INSTALLED_APPS = [
|
|||
'courses',
|
||||
'year_levels',
|
||||
'semesters',
|
||||
'subjects',
|
||||
]
|
||||
|
||||
MIDDLEWARE = [
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
# Generated by Django 4.2.2 on 2023-06-27 05:57
|
||||
# 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):
|
||||
|
@ -15,8 +16,15 @@ class Migration(migrations.Migration):
|
|||
name='Course',
|
||||
fields=[
|
||||
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||
('course_name', models.CharField(max_length=64)),
|
||||
('course_shortname', models.CharField(max_length=16)),
|
||||
('name', models.CharField(max_length=64)),
|
||||
('shortname', models.CharField(max_length=16)),
|
||||
],
|
||||
),
|
||||
migrations.CreateModel(
|
||||
name='SubjectCourse',
|
||||
fields=[
|
||||
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||
('course', models.ForeignKey(null=True, on_delete=django.db.models.deletion.CASCADE, to='courses.course')),
|
||||
],
|
||||
),
|
||||
]
|
||||
|
|
27
stude/courses/migrations/0002_initial.py
Normal file
27
stude/courses/migrations/0002_initial.py
Normal file
|
@ -0,0 +1,27 @@
|
|||
# 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 = [
|
||||
('courses', '0001_initial'),
|
||||
('subjects', '0001_initial'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name='subjectcourse',
|
||||
name='subject',
|
||||
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='subjects.subject'),
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='course',
|
||||
name='subjects',
|
||||
field=models.ManyToManyField(related_name='SubjectCourse_course', through='courses.SubjectCourse', to='subjects.subject'),
|
||||
),
|
||||
]
|
|
@ -1,23 +0,0 @@
|
|||
# Generated by Django 4.2.2 on 2023-06-27 07:31
|
||||
|
||||
from django.db import migrations
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('courses', '0001_initial'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.RenameField(
|
||||
model_name='course',
|
||||
old_name='course_name',
|
||||
new_name='name',
|
||||
),
|
||||
migrations.RenameField(
|
||||
model_name='course',
|
||||
old_name='course_shortname',
|
||||
new_name='shortname',
|
||||
),
|
||||
]
|
|
@ -1,17 +1,25 @@
|
|||
from django.db import models
|
||||
from django.db.models.signals import post_migrate
|
||||
from django.dispatch import receiver
|
||||
from django.db import models
|
||||
# Create your models here.
|
||||
|
||||
|
||||
class Course(models.Model):
|
||||
name = models.CharField(max_length=64)
|
||||
shortname = models.CharField(max_length=16)
|
||||
subjects = models.ManyToManyField(
|
||||
'subjects.Subject', related_name='SubjectCourse_course', through='courses.SubjectCourse')
|
||||
|
||||
def __str__(self):
|
||||
return self.name
|
||||
|
||||
|
||||
class SubjectCourse(models.Model):
|
||||
subject = models.ForeignKey('subjects.Subject', on_delete=models.CASCADE)
|
||||
course = models.ForeignKey(
|
||||
'courses.Course', on_delete=models.CASCADE, null=True)
|
||||
|
||||
|
||||
@receiver(post_migrate)
|
||||
def populate_courses(sender, **kwargs):
|
||||
if sender.name == 'courses':
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
# Generated by Django 4.2.2 on 2023-06-27 07:45
|
||||
# Generated by Django 4.2.2 on 2023-06-27 09:44
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
|
|
@ -14,10 +14,10 @@ class Semester(models.Model):
|
|||
|
||||
|
||||
@receiver(post_migrate)
|
||||
def populate_courses(sender, **kwargs):
|
||||
def populate_semesters(sender, **kwargs):
|
||||
if sender.name == 'semesters':
|
||||
Semester.objects.get_or_create(
|
||||
name='1st Semester', shortname='1st')
|
||||
name='1st Semester', shortname='1stSem')
|
||||
Semester.objects.get_or_create(
|
||||
name='2nd Semester', shortname='2nd')
|
||||
name='2nd Semester', shortname='2ndSem')
|
||||
# Add more predefined records as needed
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
# Generated by Django 4.2.2 on 2023-06-27 05:15
|
||||
# Generated by Django 4.2.2 on 2023-06-27 09:44
|
||||
|
||||
from django.conf import settings
|
||||
from django.db import migrations, models
|
||||
|
|
0
stude/subjects/__init__.py
Normal file
0
stude/subjects/__init__.py
Normal file
5
stude/subjects/admin.py
Normal file
5
stude/subjects/admin.py
Normal file
|
@ -0,0 +1,5 @@
|
|||
from django.contrib import admin
|
||||
from .models import Subject
|
||||
|
||||
|
||||
admin.site.register(Subject)
|
6
stude/subjects/apps.py
Normal file
6
stude/subjects/apps.py
Normal file
|
@ -0,0 +1,6 @@
|
|||
from django.apps import AppConfig
|
||||
|
||||
|
||||
class SubjectsConfig(AppConfig):
|
||||
default_auto_field = 'django.db.models.BigAutoField'
|
||||
name = 'subjects'
|
29
stude/subjects/migrations/0001_initial.py
Normal file
29
stude/subjects/migrations/0001_initial.py
Normal file
|
@ -0,0 +1,29 @@
|
|||
# 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 = [
|
||||
('year_levels', '0001_initial'),
|
||||
('courses', '0001_initial'),
|
||||
('semesters', '0001_initial'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.CreateModel(
|
||||
name='Subject',
|
||||
fields=[
|
||||
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||
('name', models.CharField(max_length=64)),
|
||||
('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')),
|
||||
],
|
||||
),
|
||||
]
|
0
stude/subjects/migrations/__init__.py
Normal file
0
stude/subjects/migrations/__init__.py
Normal file
26
stude/subjects/models.py
Normal file
26
stude/subjects/models.py
Normal file
|
@ -0,0 +1,26 @@
|
|||
from django.db import models
|
||||
from year_levels.models import Year_Level
|
||||
from semesters.models import Semester
|
||||
# Create your models here.
|
||||
|
||||
|
||||
class Subject(models.Model):
|
||||
name = models.CharField(max_length=64)
|
||||
code = models.CharField(max_length=16)
|
||||
courses = models.ManyToManyField(
|
||||
'courses.Course', through='courses.SubjectCourse', related_name='SubjectCourse_subject')
|
||||
|
||||
year_level = models.ForeignKey(
|
||||
Year_Level,
|
||||
on_delete=models.SET_NULL,
|
||||
null=True,
|
||||
related_name='Year_Level_name'
|
||||
)
|
||||
semester = models.ForeignKey(
|
||||
Semester,
|
||||
on_delete=models.SET_NULL,
|
||||
null=True
|
||||
)
|
||||
|
||||
def __str__(self):
|
||||
return self.name
|
19
stude/subjects/serializers.py
Normal file
19
stude/subjects/serializers.py
Normal file
|
@ -0,0 +1,19 @@
|
|||
from rest_framework import serializers
|
||||
from .models import Subject
|
||||
from year_levels.serializers import YearLevelSerializer
|
||||
from semesters.serializers import SemesterSerializer
|
||||
|
||||
|
||||
class SubjectSerializer(serializers.ModelSerializer):
|
||||
year_level = serializers.SerializerMethodField()
|
||||
semester = serializers.SerializerMethodField()
|
||||
|
||||
class Meta:
|
||||
model = Subject
|
||||
fields = '__all__'
|
||||
|
||||
def get_year_level(self, obj):
|
||||
return obj.year_level.name
|
||||
|
||||
def get_semester(self, obj):
|
||||
return obj.semester.name
|
3
stude/subjects/tests.py
Normal file
3
stude/subjects/tests.py
Normal file
|
@ -0,0 +1,3 @@
|
|||
from django.test import TestCase
|
||||
|
||||
# Create your tests here.
|
9
stude/subjects/urls.py
Normal file
9
stude/subjects/urls.py
Normal file
|
@ -0,0 +1,9 @@
|
|||
from django.urls import include, path
|
||||
from .views import SubjectListView
|
||||
from .views import SubjectByYearSemesterView
|
||||
|
||||
urlpatterns = [
|
||||
path('', SubjectListView.as_view()),
|
||||
path('subjects/<str:year_slug>/',
|
||||
SubjectByYearSemesterView.as_view()),
|
||||
]
|
22
stude/subjects/views.py
Normal file
22
stude/subjects/views.py
Normal file
|
@ -0,0 +1,22 @@
|
|||
from rest_framework import generics
|
||||
from .models import Subject
|
||||
from .serializers import SubjectSerializer
|
||||
from rest_framework.views import APIView
|
||||
from rest_framework.response import Response
|
||||
|
||||
|
||||
class SubjectListView(generics.ListAPIView):
|
||||
serializer_class = SubjectSerializer
|
||||
queryset = Subject.objects.all()
|
||||
|
||||
|
||||
class SubjectByYearSemesterView(generics.ListAPIView):
|
||||
def get(self, request, year_slug):
|
||||
# Retrieve the subjects based on year level and semester slugs
|
||||
subjects = Subject.objects.filter(
|
||||
year_level__shortname=year_slug)
|
||||
|
||||
# Serialize the subjects
|
||||
serializer = SubjectSerializer(subjects, many=True)
|
||||
|
||||
return Response(serializer.data)
|
|
@ -1,4 +1,4 @@
|
|||
# Generated by Django 4.2.2 on 2023-06-27 07:16
|
||||
# Generated by Django 4.2.2 on 2023-06-27 09:44
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
|
|
@ -17,13 +17,13 @@ class Year_Level(models.Model):
|
|||
def populate_courses(sender, **kwargs):
|
||||
if sender.name == 'year_levels':
|
||||
Year_Level.objects.get_or_create(
|
||||
name='1st Year', shortname='1st')
|
||||
name='1st Year', shortname='1stYr')
|
||||
Year_Level.objects.get_or_create(
|
||||
name='2nd Year', shortname='2nd')
|
||||
name='2nd Year', shortname='2ndYr')
|
||||
Year_Level.objects.get_or_create(
|
||||
name='3rd Year', shortname='3rd')
|
||||
name='3rd Year', shortname='3rdYr')
|
||||
Year_Level.objects.get_or_create(
|
||||
name='4th Year', shortname='3th')
|
||||
name='4th Year', shortname='4thYr')
|
||||
Year_Level.objects.get_or_create(
|
||||
name='Irregular', shortname='Irreg')
|
||||
# Add more predefined records as needed
|
||||
|
|
Loading…
Reference in a new issue