Polished subjects app

This commit is contained in:
keannu125 2023-03-21 21:50:54 +08:00
parent 8527870f90
commit 249e4e920e
3 changed files with 26 additions and 2 deletions

View file

@ -0,0 +1,18 @@
# Generated by Django 4.1.7 on 2023-03-21 13:49
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('subjects', '0001_initial'),
]
operations = [
migrations.AlterField(
model_name='subject',
name='year_level',
field=models.CharField(choices=[('IU-Y1', '1st Year'), ('IU-Y2', '2nd Year'), ('IU-Y3', '3rd Year'), ('IU-Y4', '4th Year')], max_length=20),
),
]

View file

@ -4,6 +4,12 @@ from django.core.validators import MaxValueValidator, MinValueValidator
class Subject(models.Model):
class YearLevels(models.TextChoices):
FIRST_YEAR = 'IU-Y1', '1st Year'
SECOND_YEAR = 'IU-Y2', '2nd Year'
THIRD_YEAR = 'IU-Y3', '3rd Year'
FOURTH_YEAR = 'IU-Y4', '4th Year'
name = models.CharField(max_length=40)
enrolled_count = models.IntegerField(
default=0,
@ -12,7 +18,7 @@ class Subject(models.Model):
MinValueValidator(0)
])
max_slots = models.IntegerField(default=60)
year_level = models.CharField(max_length=20)
year_level = models.CharField(max_length=20, choices=YearLevels.choices)
def __str__(self):
return self.name

View file

@ -9,4 +9,4 @@ class SubjectSerializer(serializers.HyperlinkedModelSerializer):
class Meta:
model = Subject
fields = ('id', 'name', 'enrolled_count', 'max_slots', 'year_level')
read_only_fields = ('id', 'max_slots')
read_only_fields = ('id',)