本文整理汇总了Python中forms.ArticleForm.save_m2m方法的典型用法代码示例。如果您正苦于以下问题:Python ArticleForm.save_m2m方法的具体用法?Python ArticleForm.save_m2m怎么用?Python ArticleForm.save_m2m使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类forms.ArticleForm
的用法示例。
在下文中一共展示了ArticleForm.save_m2m方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: article
# 需要导入模块: from forms import ArticleForm [as 别名]
# 或者: from forms.ArticleForm import save_m2m [as 别名]
def article(request, name = None):
context = get_context(request)
new = (name is None)
if new:
art = None
title = u'Nowy artykuł'
has_perm = request.user.has_perm('wwwapp.add_article')
else:
art = Article.objects.get(name=name)
title = art.title
has_perm = request.user.has_perm('wwwapp.change_article')
if has_perm:
if request.method == 'POST':
form = ArticleForm(request.user, request.POST, instance=art)
if form.is_valid():
article = form.save(commit=False)
article.modified_by = request.user
article.save()
form.save_m2m()
return redirect('article', form.instance.name)
else:
form = ArticleForm(request.user, instance=art)
else:
form = None
context['addArticle'] = new
context['title'] = title
context['article'] = art
context['form'] = form
return render(request, 'article.html', context)