Remove shedules field on students

This commit is contained in:
keannu125 2023-04-22 11:59:16 +08:00
parent c9c7d1f5ec
commit 98392344a1
8 changed files with 95 additions and 9 deletions

View file

@ -12,6 +12,13 @@ class Schedule(models.Model):
'professors.Professor', related_name='Professor_full_name', on_delete=models.CASCADE)
date_created = models.DateTimeField(default=now, editable=False)
@property
def name(self):
return f"{self.subject}"
def __str__(self):
return self.subject
class StudentSchedule(models.Model):
schedule = models.ForeignKey(

View file

@ -1,13 +1,31 @@
from rest_framework import serializers
from .models import Schedule
from professors.models import Professor
from students.models import Student
class ScheduleSerializer(serializers.HyperlinkedModelSerializer):
date_created = serializers.DateTimeField(
format="%d-%m-%Y %I:%M%p", read_only=True)
# students_assigned = serializers.SlugRelatedField(
# queryset=Student.objects.all(), slug_field='student_assigned', allow_null=True)
professor = serializers.SlugRelatedField(
queryset=Professor.objects.all(), slug_field='full_name', allow_null=True)
class Meta:
model = Schedule
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')

View file

@ -3,11 +3,17 @@ from django.shortcuts import render
# Create your views here.
from rest_framework.permissions import IsAuthenticated
from rest_framework import viewsets
from .serializers import ScheduleSerializer
from .models import Schedule
from .serializers import ScheduleSerializer, StudentScheduleSerializer
from .models import Schedule, StudentSchedule
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()

View file

@ -0,0 +1,19 @@
# Generated by Django 4.2 on 2023-04-22 03:05
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('schedules', '0002_alter_schedule_professor'),
('students', '0005_remove_student_enrolled_subjects'),
]
operations = [
migrations.AddField(
model_name='student',
name='schedules',
field=models.ManyToManyField(through='schedules.StudentSchedule', to='schedules.schedule'),
),
]

View file

@ -0,0 +1,19 @@
# Generated by Django 4.2 on 2023-04-22 03:24
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('schedules', '0002_alter_schedule_professor'),
('students', '0006_student_schedules'),
]
operations = [
migrations.AlterField(
model_name='student',
name='schedules',
field=models.ManyToManyField(related_name='Schedule_subject', through='schedules.StudentSchedule', to='schedules.schedule'),
),
]

View file

@ -0,0 +1,17 @@
# Generated by Django 4.2 on 2023-04-22 03:58
from django.db import migrations
class Migration(migrations.Migration):
dependencies = [
('students', '0007_alter_student_schedules'),
]
operations = [
migrations.RemoveField(
model_name='student',
name='schedules',
),
]

View file

@ -36,15 +36,15 @@ class Student(models.Model):
clearance_done = models.BooleanField()
pta_done = models.BooleanField()
#
# enrolled_subjects = models.ManyToManyField(
# 'subjects.Subject', through='subjects.SubjectStudent')
# 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)
def __str__(self):
return self.first_name
@property
def full_name(self):
return self.first_name + " " + self.middle_name + " " + self.last_name
return f"{self.first_name} {self.last_name}"
def __str__(self):
return self.full_name

View file

@ -1,7 +1,7 @@
from rest_framework import serializers
from django.contrib.auth.models import User
from .models import Student
from subjects.models import Subject
from schedules.models import Schedule
class StudentSerializer(serializers.HyperlinkedModelSerializer):