示例#1
0
def add_example(request, slug, template_name="package/add_example.html"):

    package = get_object_or_404(Package, slug=slug)
    new_package_example = PackageExample()
    form = PackageExampleForm(request.POST or None, instance=new_package_example)

    if form.is_valid():
        package_example = PackageExample(package=package, title=request.POST["title"], url=request.POST["url"])
        package_example.save()
        return HttpResponseRedirect(reverse("package", kwargs={"slug": package_example.package.slug}))

    return render(request, template_name, {"form": form, "package": package})
示例#2
0
def add_example(request, slug, template_name="package/add_example.html"):

    package = get_object_or_404(Project, slug=slug)
    new_package_example = PackageExample()
    form = PackageExampleForm(request.POST or None,
                              instance=new_package_example)

    if form.is_valid():
        package_example = PackageExample(package=package,
                                         title=request.POST["title"],
                                         url=request.POST["url"])
        package_example.save()
        return HttpResponseRedirect(
            reverse("package", kwargs={"slug": package_example.package.slug}))

    return render(request, template_name, {"form": form, "package": package})