From 00c8e6f4f4d212739f16eda124de8a9272dd548c Mon Sep 17 00:00:00 2001 From: keannu125 Date: Sat, 22 Apr 2023 14:07:08 +0800 Subject: [PATCH] Added day and timeslots --- infotech/api/urls.py | 2 +- infotech/config/settings.py | 3 +- infotech/{timeslots => daytimes}/__init__.py | 0 infotech/daytimes/admin.py | 5 +++ infotech/{timeslots => daytimes}/apps.py | 4 +-- infotech/daytimes/migrations/0001_initial.py | 24 ++++++++++++++ .../migrations/__init__.py | 0 infotech/{timeslots => daytimes}/models.py | 21 +++--------- infotech/daytimes/serializers.py | 10 ++++++ infotech/{timeslots => daytimes}/tests.py | 0 infotech/{timeslots => daytimes}/urls.py | 3 +- infotech/daytimes/views.py | 11 +++++++ infotech/schedules/models.py | 16 +++++++++ infotech/timeslots/admin.py | 6 ---- infotech/timeslots/migrations/0001_initial.py | 33 ------------------- infotech/timeslots/serializers.py | 20 ----------- infotech/timeslots/views.py | 17 ---------- 17 files changed, 76 insertions(+), 99 deletions(-) rename infotech/{timeslots => daytimes}/__init__.py (100%) create mode 100644 infotech/daytimes/admin.py rename infotech/{timeslots => daytimes}/apps.py (59%) create mode 100644 infotech/daytimes/migrations/0001_initial.py rename infotech/{timeslots => daytimes}/migrations/__init__.py (100%) rename infotech/{timeslots => daytimes}/models.py (60%) create mode 100644 infotech/daytimes/serializers.py rename infotech/{timeslots => daytimes}/tests.py (100%) rename infotech/{timeslots => daytimes}/urls.py (69%) create mode 100644 infotech/daytimes/views.py delete mode 100644 infotech/timeslots/admin.py delete mode 100644 infotech/timeslots/migrations/0001_initial.py delete mode 100644 infotech/timeslots/serializers.py delete mode 100644 infotech/timeslots/views.py diff --git a/infotech/api/urls.py b/infotech/api/urls.py index 17f9acc..acf97e5 100644 --- a/infotech/api/urls.py +++ b/infotech/api/urls.py @@ -6,6 +6,6 @@ urlpatterns = [ path('', include('students.urls')), path('', include('professors.urls')), path('', include('schedules.urls')), - path('', include('timeslots.urls')), + path('', include('daytimes.urls')), path('accounts/', include('accounts.urls')), ] diff --git a/infotech/config/settings.py b/infotech/config/settings.py index 5dfdfe1..80d98a6 100644 --- a/infotech/config/settings.py +++ b/infotech/config/settings.py @@ -47,7 +47,8 @@ INSTALLED_APPS = [ 'students', 'professors', 'schedules', - 'timeslots', + 'daytimes', + ] MIDDLEWARE = [ diff --git a/infotech/timeslots/__init__.py b/infotech/daytimes/__init__.py similarity index 100% rename from infotech/timeslots/__init__.py rename to infotech/daytimes/__init__.py diff --git a/infotech/daytimes/admin.py b/infotech/daytimes/admin.py new file mode 100644 index 0000000..8273f57 --- /dev/null +++ b/infotech/daytimes/admin.py @@ -0,0 +1,5 @@ +from django.contrib import admin +from .models import DayTime + +# Register your models here. +admin.register(DayTime) diff --git a/infotech/timeslots/apps.py b/infotech/daytimes/apps.py similarity index 59% rename from infotech/timeslots/apps.py rename to infotech/daytimes/apps.py index 3e88617..15081df 100644 --- a/infotech/timeslots/apps.py +++ b/infotech/daytimes/apps.py @@ -1,6 +1,6 @@ from django.apps import AppConfig -class TimeslotsConfig(AppConfig): +class DaytimesConfig(AppConfig): default_auto_field = 'django.db.models.BigAutoField' - name = 'timeslots' + name = 'daytimes' diff --git a/infotech/daytimes/migrations/0001_initial.py b/infotech/daytimes/migrations/0001_initial.py new file mode 100644 index 0000000..bfec33b --- /dev/null +++ b/infotech/daytimes/migrations/0001_initial.py @@ -0,0 +1,24 @@ +# Generated by Django 4.2 on 2023-04-22 06:04 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + initial = True + + dependencies = [ + ] + + operations = [ + migrations.CreateModel( + name='DayTime', + fields=[ + ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('name', models.TextField()), + ('day', models.TextField(choices=[('Monday', 'Monday'), ('Tuesday', 'Tuesday'), ('Wednesday', 'Wednesday'), ('Thursday', 'Thursday'), ('Friday', 'Friday'), ('Saturday', 'Saturday'), ('Sunday', 'Sunday')])), + ('time_start', models.TimeField(max_length=40)), + ('time_end', models.TimeField(max_length=20)), + ], + ), + ] diff --git a/infotech/timeslots/migrations/__init__.py b/infotech/daytimes/migrations/__init__.py similarity index 100% rename from infotech/timeslots/migrations/__init__.py rename to infotech/daytimes/migrations/__init__.py diff --git a/infotech/timeslots/models.py b/infotech/daytimes/models.py similarity index 60% rename from infotech/timeslots/models.py rename to infotech/daytimes/models.py index 39e0d79..5c3e6ad 100644 --- a/infotech/timeslots/models.py +++ b/infotech/daytimes/models.py @@ -4,20 +4,7 @@ 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 DayTime(models.Model): class Days(models.TextChoices): Monday = 'Monday' Tuesday = 'Tuesday' @@ -29,11 +16,11 @@ class TimeSchedule(models.Model): name = models.TextField() day = models.TextField(choices=Days.choices) - time_window = models.ForeignKey( - TimeSlot, on_delete=models.CASCADE) + time_start = models.TimeField(max_length=40) + time_end = models.TimeField(max_length=20) def save(self, *args, **kwargs): - self.name = f"{self.day} - {self.time_window}" + self.name = f"{self.day} : {self.time_start} - {self.time_end}" super().save(*args, **kwargs) def __str__(self): diff --git a/infotech/daytimes/serializers.py b/infotech/daytimes/serializers.py new file mode 100644 index 0000000..848ca88 --- /dev/null +++ b/infotech/daytimes/serializers.py @@ -0,0 +1,10 @@ +from rest_framework import serializers +from django.contrib.auth.models import User +from .models import DayTime + + +class DayTimeSerializer(serializers.HyperlinkedModelSerializer): + class Meta: + model = DayTime + fields = ('id', 'name', 'day', 'time_start', 'time_end') + read_only_fields = ['id', 'name'] diff --git a/infotech/timeslots/tests.py b/infotech/daytimes/tests.py similarity index 100% rename from infotech/timeslots/tests.py rename to infotech/daytimes/tests.py diff --git a/infotech/timeslots/urls.py b/infotech/daytimes/urls.py similarity index 69% rename from infotech/timeslots/urls.py rename to infotech/daytimes/urls.py index f6acf05..86b118a 100644 --- a/infotech/timeslots/urls.py +++ b/infotech/daytimes/urls.py @@ -3,8 +3,7 @@ from rest_framework import routers from . import views router = routers.DefaultRouter() -router.register(r'timeslots', views.TimeSlotViewSet) -router.register(r'timeschedules', views.TimeScheduleViewSet) +router.register(r'daytimes', views.DayTimeViewSet) # Wire up our API using automatic URL routing. # Additionally, we include login URLs for the browsable API. urlpatterns = [ diff --git a/infotech/daytimes/views.py b/infotech/daytimes/views.py new file mode 100644 index 0000000..6b4d89d --- /dev/null +++ b/infotech/daytimes/views.py @@ -0,0 +1,11 @@ +from rest_framework import viewsets, generics +from .models import DayTime +from .serializers import DayTimeSerializer + +# Create your views here. + + +class DayTimeViewSet(viewsets.ModelViewSet): + # permission_classes = [IsAuthenticated] + serializer_class = DayTimeSerializer + queryset = DayTime.objects.all() diff --git a/infotech/schedules/models.py b/infotech/schedules/models.py index a63e1db..4dfcaec 100644 --- a/infotech/schedules/models.py +++ b/infotech/schedules/models.py @@ -10,6 +10,9 @@ class Schedule(models.Model): 'students.Student', related_name='StudentSchedule_student_assigned', through='schedules.StudentSchedule') professor = models.OneToOneField( 'professors.Professor', related_name='Professor_full_name', on_delete=models.CASCADE) + # daytimes = models.ForeignKey( + # 'daytimes.DayTime', related_name='DayTime_full_name', on_delete=models.CASCADE) + date_created = models.DateTimeField(default=now, editable=False) @property @@ -29,3 +32,16 @@ class StudentSchedule(models.Model): def __str__(self): return self.schedule + + +''' +class DayTimeSchedule(models.Model): + schedule = models.ForeignKey( + 'schedules.Schedule', on_delete=models.CASCADE) + timeschedule = models.ForeignKey( + 'daytimes.DayTime', on_delete=models.CASCADE) + + def __str__(self): + return self.schedule + +''' diff --git a/infotech/timeslots/admin.py b/infotech/timeslots/admin.py deleted file mode 100644 index 8bbc8bd..0000000 --- a/infotech/timeslots/admin.py +++ /dev/null @@ -1,6 +0,0 @@ -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/migrations/0001_initial.py b/infotech/timeslots/migrations/0001_initial.py deleted file mode 100644 index 8aab098..0000000 --- a/infotech/timeslots/migrations/0001_initial.py +++ /dev/null @@ -1,33 +0,0 @@ -# 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/serializers.py b/infotech/timeslots/serializers.py deleted file mode 100644 index 04b4d27..0000000 --- a/infotech/timeslots/serializers.py +++ /dev/null @@ -1,20 +0,0 @@ -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/views.py b/infotech/timeslots/views.py deleted file mode 100644 index da0cf19..0000000 --- a/infotech/timeslots/views.py +++ /dev/null @@ -1,17 +0,0 @@ -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()