Created students app

This commit is contained in:
keannu125 2023-03-21 21:49:26 +08:00
parent 4c8eb00197
commit 8527870f90
12 changed files with 129 additions and 1 deletions

View file

@ -3,5 +3,6 @@ from django.urls import path, include
urlpatterns = [ urlpatterns = [
path('', include('subjects.urls')), path('', include('subjects.urls')),
path('', include('students.urls')),
path('accounts/', include('accounts.urls')), path('accounts/', include('accounts.urls')),
] ]

View file

@ -42,7 +42,8 @@ INSTALLED_APPS = [
'rest_framework', 'rest_framework',
'rest_framework.authtoken', 'rest_framework.authtoken',
'djoser', 'djoser',
'subjects' 'subjects',
'students'
] ]
MIDDLEWARE = [ MIDDLEWARE = [

View file

View file

@ -0,0 +1,3 @@
from django.contrib import admin
# Register your models here.

View file

@ -0,0 +1,6 @@
from django.apps import AppConfig
class StudentsConfig(AppConfig):
default_auto_field = 'django.db.models.BigAutoField'
name = 'students'

View file

@ -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)),
],
),
]

View file

View file

@ -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

View file

@ -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']

View file

@ -0,0 +1,3 @@
from django.test import TestCase
# Create your tests here.

12
infotech/students/urls.py Normal file
View file

@ -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)),
]

View file

@ -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()