Пример #1
0
def add_robot(request):
    if request.method == "POST":
        form = RobotForm(request.POST)
        if form.is_valid():
            form.save()
            return HttpResponseRedirect("/robot/")
    else:
        form = RobotForm()
        parts = Part.objects.all().order_by("id")
        chassis_list = Chassis.objects.all().order_by("id")
        t = loader.get_template("robot_edit.tmpl")
        c = RequestContext(request, {"form": form, "parts": parts, "chassis_list": chassis_list, "action": "add"})
        return HttpResponse(t.render(c))
Пример #2
0
def edit_robot(request, pk):
    if request.method == "POST":
        robot = Robot.objects.get(id=pk)
        form = RobotForm(request.POST, instance=robot)
        if form.is_valid():
            form.save()
            return HttpResponseRedirect("/robot/")
    else:
        robot = Robot.objects.get(id=pk)
        form = RobotForm(instance=robot)
        parts = Part.objects.all().order_by("id")
        chassis_list = Chassis.objects.all().order_by("id")
        t = loader.get_template("robot_edit.tmpl")
        c = RequestContext(
            request, {"form": form, "parts": parts, "chassis_list": chassis_list, "action": pk + "/edit"}
        )
        return HttpResponse(t.render(c))