diff --git a/infotech/api/urls.py b/infotech/api/urls.py index ad97463..43755cc 100644 --- a/infotech/api/urls.py +++ b/infotech/api/urls.py @@ -3,5 +3,6 @@ from django.urls import path, include urlpatterns = [ path('', include('subjects.urls')), + path('', include('students.urls')), path('accounts/', include('accounts.urls')), ] diff --git a/infotech/config/settings.py b/infotech/config/settings.py index eaec162..2da7b7c 100644 --- a/infotech/config/settings.py +++ b/infotech/config/settings.py @@ -42,7 +42,8 @@ INSTALLED_APPS = [ 'rest_framework', 'rest_framework.authtoken', 'djoser', - 'subjects' + 'subjects', + 'students' ] MIDDLEWARE = [ diff --git a/infotech/students/__init__.py b/infotech/students/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/infotech/students/admin.py b/infotech/students/admin.py new file mode 100644 index 0000000..ea5d68b --- /dev/null +++ b/infotech/students/admin.py @@ -0,0 +1,3 @@ +from django.contrib import admin + +# Register your models here. diff --git a/infotech/students/apps.py b/infotech/students/apps.py new file mode 100644 index 0000000..4007e1e --- /dev/null +++ b/infotech/students/apps.py @@ -0,0 +1,6 @@ +from django.apps import AppConfig + + +class StudentsConfig(AppConfig): + default_auto_field = 'django.db.models.BigAutoField' + name = 'students' diff --git a/infotech/students/migrations/0001_initial.py b/infotech/students/migrations/0001_initial.py new file mode 100644 index 0000000..d82288c --- /dev/null +++ b/infotech/students/migrations/0001_initial.py @@ -0,0 +1,35 @@ +# Generated by Django 4.1.7 on 2023-03-21 13:47 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + initial = True + + dependencies = [ + ] + + operations = [ + migrations.CreateModel( + name='Student', + fields=[ + ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('first_name', models.CharField(max_length=40)), + ('middle_name', models.CharField(max_length=40)), + ('last_name', models.CharField(max_length=40)), + ('age', models.IntegerField()), + ('sex', models.CharField(choices=[('M', 'Male'), ('F', 'Female')], max_length=1)), + ('birthdate', models.DateField()), + ('address', models.CharField(max_length=150)), + ('birthplace', models.CharField(max_length=150)), + ('mother_name', models.CharField(max_length=80)), + ('father_name', models.CharField(max_length=80)), + ('registrar_done', models.BooleanField()), + ('clearance_done', models.BooleanField()), + ('pta_done', models.BooleanField()), + ('enrolled_subjects', models.CharField(max_length=800)), + ('year_level', models.CharField(choices=[('IU-Y1', '1st Year'), ('IU-Y2', '2nd Year'), ('IU-Y3', '3rd Year'), ('IU-Y4', '4th Year')], max_length=20)), + ], + ), + ] diff --git a/infotech/students/migrations/__init__.py b/infotech/students/migrations/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/infotech/students/models.py b/infotech/students/models.py new file mode 100644 index 0000000..f8d659d --- /dev/null +++ b/infotech/students/models.py @@ -0,0 +1,40 @@ +from django.db import models +from django.contrib.postgres.fields import ArrayField +# Create your models here. + + +class Student(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' + + class SexChoices(models.TextChoices): + MALE = 'M', 'Male' + FEMALE = 'F', 'Female' + + first_name = models.CharField(max_length=40) + middle_name = models.CharField(max_length=40) + last_name = models.CharField(max_length=40) + # + age = models.IntegerField() + sex = models.CharField(max_length=1, choices=SexChoices.choices) + birthdate = models.DateField() + # + address = models.CharField(max_length=150) + birthplace = models.CharField(max_length=150) + # + mother_name = models.CharField(max_length=80) + father_name = models.CharField(max_length=80) + # + registrar_done = models.BooleanField() + clearance_done = models.BooleanField() + pta_done = models.BooleanField() + # + enrolled_subjects = models.CharField(max_length=800) + year_level = models.CharField(max_length=20, choices=YearLevels.choices) + + def __str__(self): + return self.name diff --git a/infotech/students/serializers.py b/infotech/students/serializers.py new file mode 100644 index 0000000..c32698a --- /dev/null +++ b/infotech/students/serializers.py @@ -0,0 +1,17 @@ +from rest_framework import serializers +from django.contrib.auth.models import User +from .models import Student + + +class StudentSerializer(serializers.HyperlinkedModelSerializer): + + class Meta: + model = Student + fields = ['id', 'first_name', 'middle_name', 'last_name', + 'age', 'sex', 'birthdate', + 'address', 'birthplace', + 'mother_name', 'father_name', + 'registrar_done', 'clearance_done', 'pta_done', + 'enrolled_subjects', 'year_level' + ] + read_only_fields = ['id'] diff --git a/infotech/students/tests.py b/infotech/students/tests.py new file mode 100644 index 0000000..de8bdc0 --- /dev/null +++ b/infotech/students/tests.py @@ -0,0 +1,3 @@ +from django.test import TestCase + +# Create your tests here. diff --git a/infotech/students/urls.py b/infotech/students/urls.py new file mode 100644 index 0000000..87fca95 --- /dev/null +++ b/infotech/students/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'students', views.StudentViewSet) + +# 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/students/views.py b/infotech/students/views.py new file mode 100644 index 0000000..2ec2125 --- /dev/null +++ b/infotech/students/views.py @@ -0,0 +1,10 @@ +from rest_framework.permissions import IsAuthenticated +from rest_framework import viewsets +from .serializers import StudentSerializer +from .models import Student + + +class StudentViewSet(viewsets.ModelViewSet): + # permission_classes = [IsAuthenticated] + serializer_class = StudentSerializer + queryset = Student.objects.all()