def update_assignment(request, id=None): obj = get_object_or_404(ClassAssignment, id=id) form = AssignmentForm(request.POST or None, instance=obj) context = {"form": form} if form.is_valid(): obj = form.save(commit=False) if 'assignment' in request.FILES: obj.assignment = request.FILES['assignment'] obj.save() messages.success(request, "Updated Assignment".format(obj.assignment_name)) return redirect('classroom:assignment_list') template = "classroom/update_assignment.html" return render(request, template, context)
def upload_assignment(request): assignment_uploaded = False teacher = request.user.Teacher students = Student.objects.filter(user_student_name__teacher=request.user.Teacher) if request.method == 'POST': form = AssignmentForm(request.POST, request.FILES) if form.is_valid(): upload = form.save(commit=False) upload.teacher = teacher students = Student.objects.filter(user_student_name__teacher=request.user.Teacher) upload.save() upload.student.add(*students) assignment_uploaded = True else: form = AssignmentForm() return render(request,'classroom/upload_assignment.html',{'form':form,'assignment_uploaded':assignment_uploaded})