示例#1
0
def new_developer(request):
    if request.method == "POST":
        form = DeveloperForm(request.POST or None)
        if form.is_valid():
            if form.save():
                return redirect("/developers")
    else:
        form = DeveloperForm()
    data = {"form": form}
    return render(request, "developer/new_developer.html", data)
示例#2
0
def edit_developer(request, developer_id):
    developer = Developer.objects.get(id=developer_id)
    if request.method == "POST":
        form = DeveloperForm(request.POST, instance=developer)
        if form.is_valid():
            if form.save():
                return redirect("/developers/{}".format(developer_id))
    else:
        form = DeveloperForm(instance=developer)
    data = {"developer": developer, "form": form}
    return render(request, "developer/edit_developer.html", data)