You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

65 lines
1.3 KiB

from django.shortcuts import render
from django.http import HttpResponse
from .forms import GradesForm
from .models import StudentModel
def add_grades(request):
form = GradesForm(request.POST or None)
if request.method == 'POST':
if form.is_valid():
# grades_int = list(map(int, form.cleaned_data['grades'].split(',')))
student = StudentModel(
name=form.cleaned_data['name'],
grades=form.cleaned_data['grades'],
)
student.save()
context = {
'student': student,
}
return render(
request,
template_name='show_student.html',
context=context,
)
return render(
request,
template_name='add_student.html',
context={'form': form}
)
def get_grades(request):
grades = StudentModel.objects.all()
context = {
'grades': grades,
}
return render(
request,
template_name='show_grades.html',
context=context,
)
def get_student(request, student_id):
grades = StudentModel.objects.get(id=student_id)
context = {
'grades': grades,
}
return render(
request,
template_name='show_student.html',
context=context,
)