Added semesters

This commit is contained in:
Keannu Bernasol 2023-06-27 15:48:43 +08:00
parent ceba84acb5
commit de1dabf53c
16 changed files with 119 additions and 21 deletions

View file

@ -0,0 +1,26 @@
# 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'),
),
]

View file

@ -6,6 +6,7 @@ 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
@ -19,19 +20,6 @@ def validate_student_id(value):
class CustomUser(AbstractUser):
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'),
)
def _get_upload_to(instance, filename):
base_filename, file_extension = os.path.splitext(filename)
# Convert filename to a slug format
@ -52,21 +40,22 @@ class CustomUser(AbstractUser):
is_banned = models.BooleanField(default=False)
student_id_number = models.CharField(
max_length=16, validators=[validate_student_id], null=False)
year_level = models.CharField(
max_length=50, choices=YEAR_LEVELS)
semester = models.CharField(
max_length=50, choices=SEMESTERS)
avatar = models.ImageField(upload_to=_get_upload_to, null=True)
course = models.ForeignKey(
Course,
on_delete=models.CASCADE,
null=True
)
semester = models.ForeignKey(
year_level = models.ForeignKey(
Year_Level,
on_delete=models.CASCADE,
null=True
)
semester = models.ForeignKey(
Semester,
on_delete=models.CASCADE,
null=True
)
@property
def full_name(self):

View file

@ -5,5 +5,6 @@ urlpatterns = [
path('accounts/', include('accounts.urls')),
path('student_status/', include('student_status.urls')),
path('courses/', include('courses.urls')),
path('year_levels/', include('year_levels.urls'))
path('year_levels/', include('year_levels.urls')),
path('semesters/', include('semesters.urls'))
]

View file

@ -65,6 +65,7 @@ INSTALLED_APPS = [
'student_status',
'courses',
'year_levels',
'semesters',
]
MIDDLEWARE = [

View file

@ -9,7 +9,7 @@ class Course(models.Model):
shortname = models.CharField(max_length=16)
def __str__(self):
return self.shortname
return self.name
@receiver(post_migrate)

View file

5
stude/semesters/admin.py Normal file
View file

@ -0,0 +1,5 @@
from django.contrib import admin
from .models import Semester
admin.site.register(Semester)

6
stude/semesters/apps.py Normal file
View file

@ -0,0 +1,6 @@
from django.apps import AppConfig
class SemestersConfig(AppConfig):
default_auto_field = 'django.db.models.BigAutoField'
name = 'semesters'

View file

@ -0,0 +1,22 @@
# Generated by Django 4.2.2 on 2023-06-27 07:45
from django.db import migrations, models
class Migration(migrations.Migration):
initial = True
dependencies = [
]
operations = [
migrations.CreateModel(
name='Semester',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('name', models.CharField(max_length=64)),
('shortname', models.CharField(max_length=16)),
],
),
]

View file

23
stude/semesters/models.py Normal file
View file

@ -0,0 +1,23 @@
from django.db import models
from django.db.models.signals import post_migrate
from django.dispatch import receiver
# Create your models here.
class Semester(models.Model):
name = models.CharField(max_length=64)
shortname = models.CharField(max_length=16)
def __str__(self):
return self.name
@receiver(post_migrate)
def populate_courses(sender, **kwargs):
if sender.name == 'semesters':
Semester.objects.get_or_create(
name='1st Semester', shortname='1st')
Semester.objects.get_or_create(
name='2nd Semester', shortname='2nd')
# Add more predefined records as needed

View file

@ -0,0 +1,8 @@
from rest_framework import serializers
from .models import Semester
class SemesterSerializer(serializers.ModelSerializer):
class Meta:
model = Semester
fields = '__all__'

3
stude/semesters/tests.py Normal file
View file

@ -0,0 +1,3 @@
from django.test import TestCase
# Create your tests here.

6
stude/semesters/urls.py Normal file
View file

@ -0,0 +1,6 @@
from django.urls import include, path
from .views import SemesterListView
urlpatterns = [
path('', SemesterListView.as_view()),
]

8
stude/semesters/views.py Normal file
View file

@ -0,0 +1,8 @@
from rest_framework import generics
from .models import Semester
from .serializers import SemesterSerializer
class SemesterListView(generics.ListAPIView):
serializer_class = SemesterSerializer
queryset = Semester.objects.all()

View file

@ -10,7 +10,7 @@ class Year_Level(models.Model):
shortname = models.CharField(max_length=16)
def __str__(self):
return self.shortname
return self.name
@receiver(post_migrate)