【发布时间】:2019-09-29 20:41:12
【问题描述】:
我的模型中有多个字段选择。我想在我看来改变雕像的价值。我读了这些article 和这个question。在这些链接中,假设有两种方式:
- 创建另一个模型
- MultipleChoiceField
如果我想使用 MultipleChoiceField,我必须做什么?我阅读了这些链接:1、2、3、4、5 和6;但没有一个是云帮助我,我什么也不懂。 这也是我的代码:
#models.py
STATUE_CHOICE = (
('draft', 'draft'),
('future', 'future'),
('trash', 'trash'),
('publish', 'publish'),
)
statue = models.CharField(max_length=10, choices=STATUE_CHOICE)
#views.ppy
def delete_admin_trash_post(request, slug):
post = get_object_or_404(Post, slug=slug)
if request.method =="POST":
form = AddPostForm(request.POST, instance=post)
post.statue = 'trash'
post.save()
return redirect('view_admin_post')
else:
form = AddPostForm(instance=post)
template = 'blog/admin_blog/delete_admin_trash_post.html'
context = {'form': form}
return render(request, template, context)
这个方法能不能简单完整的解释一下?
【问题讨论】:
-
这应该是
ChoiceField,而不是MultipleChoiceField,因为您可能只能设置一个single状态。 -
我真的对方式2一无所知。所以可能我把第二种方法的名称写错是很常见的。另一个注意事项是:什么是单身雕像?这能满足我的需要吗? @WillemVanOnsem
标签: python django django-views