mirror of
https://github.com/lemeow125/StudE-Backend.git
synced 2024-11-17 06:19:24 +08:00
Further polishing for subject
This commit is contained in:
parent
492a605557
commit
c4bca9777c
3 changed files with 13 additions and 3 deletions
|
@ -1,5 +1,6 @@
|
||||||
from django.contrib import admin
|
from django.contrib import admin
|
||||||
from .models import Course
|
from .models import Course, SubjectCourse
|
||||||
|
|
||||||
|
|
||||||
admin.site.register(Course)
|
admin.site.register(Course)
|
||||||
|
admin.site.register(SubjectCourse)
|
||||||
|
|
|
@ -1,5 +1,10 @@
|
||||||
from django.contrib import admin
|
from django.contrib import admin
|
||||||
|
from courses.models import Course
|
||||||
from .models import Subject
|
from .models import Subject
|
||||||
|
|
||||||
|
|
||||||
admin.site.register(Subject)
|
class SubjectAdmin(admin.ModelAdmin):
|
||||||
|
filter_horizontal = ['courses']
|
||||||
|
|
||||||
|
|
||||||
|
admin.site.register(Subject, SubjectAdmin)
|
||||||
|
|
|
@ -1,16 +1,20 @@
|
||||||
from rest_framework import serializers
|
from rest_framework import serializers
|
||||||
from .models import Subject
|
from .models import Subject
|
||||||
|
from courses.models import Course
|
||||||
from year_levels.serializers import YearLevelSerializer
|
from year_levels.serializers import YearLevelSerializer
|
||||||
from semesters.serializers import SemesterSerializer
|
from semesters.serializers import SemesterSerializer
|
||||||
|
from courses.serializers import CourseSerializer
|
||||||
|
|
||||||
|
|
||||||
class SubjectSerializer(serializers.ModelSerializer):
|
class SubjectSerializer(serializers.ModelSerializer):
|
||||||
year_level = serializers.SerializerMethodField()
|
year_level = serializers.SerializerMethodField()
|
||||||
semester = serializers.SerializerMethodField()
|
semester = serializers.SerializerMethodField()
|
||||||
|
courses = serializers.SlugRelatedField(
|
||||||
|
queryset=Course.objects.all(), many=True, slug_field='name', allow_null=True)
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
model = Subject
|
model = Subject
|
||||||
fields = '__all__'
|
fields = ('name', 'code', 'courses', 'year_level', 'semester')
|
||||||
|
|
||||||
def get_year_level(self, obj):
|
def get_year_level(self, obj):
|
||||||
return obj.year_level.name
|
return obj.year_level.name
|
||||||
|
|
Loading…
Reference in a new issue