Exemplo n.º 1
0
def create(request,id):
    data = {}
    student = Student.objects.get(pk=id)
    subject = Subject()
    subject.subject_name = request.POST.get('subject_name')
    subject.student = student
    subject.save()
    data['name'] = subject.subject_name
    data['id'] = subject.id
    return JsonResponse(data)
Exemplo n.º 2
0
def add(request):
    if request.method == "POST":
        form = request.POST
        subject = Subject()
        subject.name = form['name']
        subject.score = form['score']
        subject.student = Student.objects.get(pk=form['student'])
        subject.save()

        return redirect('subjects:subject_detail',subject.pk)
    
    students = Student.objects.all()
    context = {
        'students':students,
        'subjects':subjects
    }

    return render(request, 'subjects/addSubject.html',context)