diff --git a/infotech/api/urls.py b/infotech/api/urls.py index 8f94b5f..17f9acc 100644 --- a/infotech/api/urls.py +++ b/infotech/api/urls.py @@ -6,5 +6,6 @@ urlpatterns = [ path('', include('students.urls')), path('', include('professors.urls')), path('', include('schedules.urls')), + path('', include('timeslots.urls')), path('accounts/', include('accounts.urls')), ] diff --git a/infotech/config/settings.py b/infotech/config/settings.py index 9d51a7f..5dfdfe1 100644 --- a/infotech/config/settings.py +++ b/infotech/config/settings.py @@ -47,6 +47,7 @@ INSTALLED_APPS = [ 'students', 'professors', 'schedules', + 'timeslots', ] MIDDLEWARE = [ @@ -156,3 +157,5 @@ EMAIL_PORT = '2525' CORS_ALLOW_ALL_ORIGINS = True CORS_ALLOW_CREDENTIALS = True + +TIME_INPUT_FORMATS = ['%I:%M %p',] diff --git a/infotech/schedules/models.py b/infotech/schedules/models.py index 556b216..a63e1db 100644 --- a/infotech/schedules/models.py +++ b/infotech/schedules/models.py @@ -26,3 +26,6 @@ class StudentSchedule(models.Model): student_assigned = models.ForeignKey( 'students.Student', on_delete=models.CASCADE) date_joined = models.DateTimeField(default=now, editable=False) + + def __str__(self): + return self.schedule diff --git a/infotech/schedules/serializers.py b/infotech/schedules/serializers.py index 950f37c..3b1319d 100644 --- a/infotech/schedules/serializers.py +++ b/infotech/schedules/serializers.py @@ -23,13 +23,3 @@ class ScheduleSerializer(serializers.HyperlinkedModelSerializer): fields = ('id', 'subject', 'students_assigned', 'professor', 'date_created') read_only_fields = ('id', 'date_created') - - -class StudentScheduleSerializer(serializers.HyperlinkedModelSerializer): - date_joined = serializers.DateTimeField( - format="%d-%m-%Y %I:%M%p", read_only=True) - - class Meta: - model = Schedule - fields = ('id', 'schedule', 'student_assigned', 'date_joined') - read_only_fields = ('id', 'date_joined') diff --git a/infotech/schedules/urls.py b/infotech/schedules/urls.py index dd7d75e..26e31be 100644 --- a/infotech/schedules/urls.py +++ b/infotech/schedules/urls.py @@ -9,5 +9,4 @@ router.register(r'schedules', views.ScheduleViewSet) # Additionally, we include login URLs for the browsable API. urlpatterns = [ path('', include(router.urls)), - ] diff --git a/infotech/schedules/views.py b/infotech/schedules/views.py index dcfcf26..92fb678 100644 --- a/infotech/schedules/views.py +++ b/infotech/schedules/views.py @@ -3,7 +3,7 @@ from django.shortcuts import render # Create your views here. from rest_framework.permissions import IsAuthenticated from rest_framework import viewsets -from .serializers import ScheduleSerializer, StudentScheduleSerializer +from .serializers import ScheduleSerializer from .models import Schedule, StudentSchedule @@ -11,9 +11,3 @@ class ScheduleViewSet(viewsets.ModelViewSet): # permission_classes = [IsAuthenticated] serializer_class = ScheduleSerializer queryset = Schedule.objects.all() - - -class StudentScheduleViewSet(viewsets.ModelViewSet): - # permission_classes = [IsAuthenticated] - serializer_class = StudentScheduleSerializer - queryset = StudentSchedule.objects.all() diff --git a/infotech/students/migrations/0010_alter_student_current_semester_and_more.py b/infotech/students/migrations/0010_alter_student_current_semester_and_more.py new file mode 100644 index 0000000..36e9c00 --- /dev/null +++ b/infotech/students/migrations/0010_alter_student_current_semester_and_more.py @@ -0,0 +1,23 @@ +# Generated by Django 4.2 on 2023-04-22 05:08 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('students', '0009_student_full_name'), + ] + + operations = [ + migrations.AlterField( + model_name='student', + name='current_semester', + field=models.CharField(choices=[('1st Semester', 'First Sem'), ('2nd Semester', 'Second Sem')], default='1st Semester', max_length=20), + ), + migrations.AlterField( + model_name='student', + name='year_level', + field=models.CharField(choices=[('1st Year', 'First Year'), ('2nd Year', 'Second Year'), ('3rd Year', 'Third Year'), ('IU-Y4', '4th Year')], max_length=20), + ), + ] diff --git a/infotech/students/migrations/0011_student_schedules.py b/infotech/students/migrations/0011_student_schedules.py new file mode 100644 index 0000000..20b3eb3 --- /dev/null +++ b/infotech/students/migrations/0011_student_schedules.py @@ -0,0 +1,19 @@ +# Generated by Django 4.2 on 2023-04-22 05:25 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('schedules', '0002_alter_schedule_professor'), + ('students', '0010_alter_student_current_semester_and_more'), + ] + + operations = [ + migrations.AddField( + model_name='student', + name='schedules', + field=models.ManyToManyField(related_name='StudentSchedule_subject', through='schedules.StudentSchedule', to='schedules.schedule'), + ), + ] diff --git a/infotech/students/models.py b/infotech/students/models.py index ee06de9..c65fc99 100644 --- a/infotech/students/models.py +++ b/infotech/students/models.py @@ -37,8 +37,9 @@ class Student(models.Model): clearance_done = models.BooleanField() pta_done = models.BooleanField() # - # schedules = models.ManyToManyField( - # 'schedules.Schedule', related_name='StudentSchedule_subject', through='schedules.StudentSchedule') + schedules = models.ManyToManyField( + 'schedules.Schedule', related_name='StudentSchedule_subject', through='schedules.StudentSchedule') + # year_level = models.CharField(max_length=20, choices=YearLevels.choices) current_semester = models.CharField( max_length=20, choices=Semesters.choices, default=Semesters.FIRST_SEM) diff --git a/infotech/students/serializers.py b/infotech/students/serializers.py index cfa1735..ade9ce2 100644 --- a/infotech/students/serializers.py +++ b/infotech/students/serializers.py @@ -5,6 +5,8 @@ from schedules.models import Schedule class StudentSerializer(serializers.HyperlinkedModelSerializer): + schedules = serializers.SlugRelatedField( + queryset=Schedule.objects.all(), slug_field='schedule_subject', allow_null=True) class Meta: model = Student @@ -13,6 +15,6 @@ class StudentSerializer(serializers.HyperlinkedModelSerializer): 'address', 'birthplace', 'mother_name', 'father_name', 'registrar_done', 'clearance_done', 'pta_done', - 'year_level', 'current_semester' + 'schedules', 'year_level', 'current_semester' ] read_only_fields = ['id', 'full_name'] diff --git a/infotech/timeslots/__init__.py b/infotech/timeslots/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/infotech/timeslots/admin.py b/infotech/timeslots/admin.py new file mode 100644 index 0000000..8bbc8bd --- /dev/null +++ b/infotech/timeslots/admin.py @@ -0,0 +1,6 @@ +from django.contrib import admin +from .models import TimeSchedule, TimeSlot + +# Register your models here. +admin.register(TimeSlot) +admin.register(TimeSchedule) diff --git a/infotech/timeslots/apps.py b/infotech/timeslots/apps.py new file mode 100644 index 0000000..3e88617 --- /dev/null +++ b/infotech/timeslots/apps.py @@ -0,0 +1,6 @@ +from django.apps import AppConfig + + +class TimeslotsConfig(AppConfig): + default_auto_field = 'django.db.models.BigAutoField' + name = 'timeslots' diff --git a/infotech/timeslots/migrations/0001_initial.py b/infotech/timeslots/migrations/0001_initial.py new file mode 100644 index 0000000..8aab098 --- /dev/null +++ b/infotech/timeslots/migrations/0001_initial.py @@ -0,0 +1,33 @@ +# Generated by Django 4.2 on 2023-04-22 05:25 + +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + initial = True + + dependencies = [ + ] + + operations = [ + migrations.CreateModel( + name='TimeSlot', + fields=[ + ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('name', models.TextField()), + ('time_start', models.TimeField(max_length=40)), + ('time_end', models.TimeField(max_length=20)), + ], + ), + migrations.CreateModel( + name='TimeSchedule', + fields=[ + ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('name', models.TextField()), + ('day', models.TextField(choices=[('Monday', 'M'), ('Tuesday', 'T'), ('Wednesday', 'W'), ('Thursday', 'Th'), ('Friday', 'F'), ('Saturday', 'S'), ('Sunday', 'Sn')])), + ('time_window', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='timeslots.timeslot')), + ], + ), + ] diff --git a/infotech/timeslots/migrations/__init__.py b/infotech/timeslots/migrations/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/infotech/timeslots/models.py b/infotech/timeslots/models.py new file mode 100644 index 0000000..39e0d79 --- /dev/null +++ b/infotech/timeslots/models.py @@ -0,0 +1,40 @@ +from django.db import models +from django.core.validators import MaxValueValidator, MinValueValidator +from django.utils.timezone import now +# Create your models here. + + +class TimeSlot(models.Model): + name = models.TextField() + time_start = models.TimeField(max_length=40) + time_end = models.TimeField(max_length=20) + + def save(self, *args, **kwargs): + self.name = f"{self.time_start} - {self.time_end}" + super().save(*args, **kwargs) + + def __str__(self): + return self.name + + +class TimeSchedule(models.Model): + class Days(models.TextChoices): + Monday = 'Monday' + Tuesday = 'Tuesday' + Wednesday = 'Wednesday' + Thursday = 'Thursday' + Friday = 'Friday' + Saturday = 'Saturday' + Sunday = 'Sunday' + + name = models.TextField() + day = models.TextField(choices=Days.choices) + time_window = models.ForeignKey( + TimeSlot, on_delete=models.CASCADE) + + def save(self, *args, **kwargs): + self.name = f"{self.day} - {self.time_window}" + super().save(*args, **kwargs) + + def __str__(self): + return self.name diff --git a/infotech/timeslots/serializers.py b/infotech/timeslots/serializers.py new file mode 100644 index 0000000..04b4d27 --- /dev/null +++ b/infotech/timeslots/serializers.py @@ -0,0 +1,20 @@ +from rest_framework import serializers +from django.contrib.auth.models import User +from .models import TimeSlot, TimeSchedule + + +class TimeSlotSerializer(serializers.HyperlinkedModelSerializer): + class Meta: + model = TimeSlot + fields = ('id', 'name', 'time_start', 'time_end') + read_only_fields = ['id', 'name'] + + +class TimeScheduleSerializer(serializers.HyperlinkedModelSerializer): + time_window = serializers.SlugRelatedField( + queryset=TimeSlot.objects.all(), slug_field='name') + + class Meta: + model = TimeSchedule + fields = ('id', 'name', 'day', 'time_window') + read_only_fields = ['id', 'name'] diff --git a/infotech/timeslots/tests.py b/infotech/timeslots/tests.py new file mode 100644 index 0000000..de8bdc0 --- /dev/null +++ b/infotech/timeslots/tests.py @@ -0,0 +1,3 @@ +from django.test import TestCase + +# Create your tests here. diff --git a/infotech/timeslots/urls.py b/infotech/timeslots/urls.py new file mode 100644 index 0000000..f6acf05 --- /dev/null +++ b/infotech/timeslots/urls.py @@ -0,0 +1,12 @@ +from django.urls import include, path +from rest_framework import routers +from . import views + +router = routers.DefaultRouter() +router.register(r'timeslots', views.TimeSlotViewSet) +router.register(r'timeschedules', views.TimeScheduleViewSet) +# Wire up our API using automatic URL routing. +# Additionally, we include login URLs for the browsable API. +urlpatterns = [ + path('', include(router.urls)), +] diff --git a/infotech/timeslots/views.py b/infotech/timeslots/views.py new file mode 100644 index 0000000..da0cf19 --- /dev/null +++ b/infotech/timeslots/views.py @@ -0,0 +1,17 @@ +from rest_framework import viewsets, generics +from .models import TimeSlot, TimeSchedule +from .serializers import TimeScheduleSerializer, TimeSlotSerializer + +# Create your views here. + + +class TimeSlotViewSet(viewsets.ModelViewSet): + # permission_classes = [IsAuthenticated] + serializer_class = TimeSlotSerializer + queryset = TimeSlot.objects.all() + + +class TimeScheduleViewSet(viewsets.ModelViewSet): + # permission_classes = [IsAuthenticated] + serializer_class = TimeScheduleSerializer + queryset = TimeSchedule.objects.all()