def update(request, class_id, template_name="manage/class_update.html"): """update a class""" group = get_object_or_404(Group, pk=class_id) if request.method == 'POST': form = ClassForm(request.POST, request.FILES, instance=group) if form.is_valid(): form.save() messages.success(request, u'班级 %s 已更新' % group.name) return redirect("manage_class_list") else: form = ClassForm(instance=group) ctx = {"form": form, "class": group} return render(request, template_name, ctx)
def create(request,template_name="manage/class_create.html"): if request.method == 'POST': form = ClassForm(request.POST,request.FILES) if form.is_valid(): group = form.save(commit=False) group.creator = request.user group.school = request.user.manageSchools.latest("id") group.save() if group.id: messages.success(request, u'已成功创建班级 %s ' % group.name) return redirect("manage_class_list") else: form = ClassForm() ctx = {'form':form} return render(request, template_name, ctx)