mirror of
https://github.com/lemeow125/StudE-Backend.git
synced 2024-11-17 06:19:24 +08:00
Add course model
This commit is contained in:
parent
f0d052bc66
commit
a12e66caed
12 changed files with 72 additions and 1 deletions
|
@ -3,5 +3,6 @@ from django.urls import path, include
|
||||||
|
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
path('accounts/', include('accounts.urls')),
|
path('accounts/', include('accounts.urls')),
|
||||||
path('student_status/', include('student_status.urls'))
|
path('student_status/', include('student_status.urls')),
|
||||||
|
path('courses/', include('courses.urls'))
|
||||||
]
|
]
|
||||||
|
|
|
@ -63,6 +63,7 @@ INSTALLED_APPS = [
|
||||||
'rest_framework.authtoken',
|
'rest_framework.authtoken',
|
||||||
'accounts',
|
'accounts',
|
||||||
'student_status',
|
'student_status',
|
||||||
|
'courses',
|
||||||
]
|
]
|
||||||
|
|
||||||
MIDDLEWARE = [
|
MIDDLEWARE = [
|
||||||
|
|
0
stude/courses/__init__.py
Normal file
0
stude/courses/__init__.py
Normal file
5
stude/courses/admin.py
Normal file
5
stude/courses/admin.py
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
from django.contrib import admin
|
||||||
|
from .models import Course
|
||||||
|
|
||||||
|
|
||||||
|
admin.site.register(Course)
|
6
stude/courses/apps.py
Normal file
6
stude/courses/apps.py
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
from django.apps import AppConfig
|
||||||
|
|
||||||
|
|
||||||
|
class CoursesConfig(AppConfig):
|
||||||
|
default_auto_field = 'django.db.models.BigAutoField'
|
||||||
|
name = 'courses'
|
22
stude/courses/migrations/0001_initial.py
Normal file
22
stude/courses/migrations/0001_initial.py
Normal file
|
@ -0,0 +1,22 @@
|
||||||
|
# Generated by Django 4.2.2 on 2023-06-27 05:57
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
initial = True
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.CreateModel(
|
||||||
|
name='Course',
|
||||||
|
fields=[
|
||||||
|
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||||
|
('course_name', models.CharField(max_length=64)),
|
||||||
|
('course_shortname', models.CharField(max_length=16)),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
]
|
0
stude/courses/migrations/__init__.py
Normal file
0
stude/courses/migrations/__init__.py
Normal file
11
stude/courses/models.py
Normal file
11
stude/courses/models.py
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
from django.db import models
|
||||||
|
from accounts.models import CustomUser as User
|
||||||
|
# Create your models here.
|
||||||
|
|
||||||
|
|
||||||
|
class Course(models.Model):
|
||||||
|
course_name = models.CharField(max_length=64)
|
||||||
|
course_shortname = models.CharField(max_length=16)
|
||||||
|
|
||||||
|
def __str__(self):
|
||||||
|
return self.course_shortname
|
8
stude/courses/serializers.py
Normal file
8
stude/courses/serializers.py
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
from rest_framework import serializers
|
||||||
|
from .models import Course
|
||||||
|
|
||||||
|
|
||||||
|
class CourseSerializer(serializers.ModelSerializer):
|
||||||
|
class Meta:
|
||||||
|
model = Course
|
||||||
|
fields = '__all__'
|
3
stude/courses/tests.py
Normal file
3
stude/courses/tests.py
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
from django.test import TestCase
|
||||||
|
|
||||||
|
# Create your tests here.
|
6
stude/courses/urls.py
Normal file
6
stude/courses/urls.py
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
from django.urls import include, path
|
||||||
|
from .views import CourseListView
|
||||||
|
|
||||||
|
urlpatterns = [
|
||||||
|
path('', CourseListView.as_view()),
|
||||||
|
]
|
8
stude/courses/views.py
Normal file
8
stude/courses/views.py
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
from rest_framework import generics
|
||||||
|
from .models import Course
|
||||||
|
from .serializers import CourseSerializer
|
||||||
|
|
||||||
|
|
||||||
|
class CourseListView(generics.ListAPIView):
|
||||||
|
serializer_class = CourseSerializer
|
||||||
|
queryset = Course.objects.all()
|
Loading…
Reference in a new issue