本文整理汇总了Python中package.forms.PackageExampleForm类的典型用法代码示例。如果您正苦于以下问题:Python PackageExampleForm类的具体用法?Python PackageExampleForm怎么用?Python PackageExampleForm使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了PackageExampleForm类的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: edit_example
def edit_example(request, slug, id, template_name="package/edit_example.html"):
package_example = get_object_or_404(PackageExample, id=id)
form = PackageExampleForm(request.POST or None, instance=package_example)
if form.is_valid():
form.save()
return HttpResponseRedirect(reverse("package", kwargs={"slug": package_example.package.slug}))
return render(request, template_name, {"form": form, "package": package_example.package})
示例2: add_example
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})