class IndexView(generic.ListView):
template_name = "posts/index.html"
def get_queryset(self):
return Inspectionfile.objects.all()
class DetailView(generic.DetailView):
model = Inspectionfile
template_name = "posts/detail.html"
class createposts(CreateView):
model = posts
fields = ['title','comments']
通过createposts和表单,我可以填充标题和注释,但是它们没有与任何Inspectionfile(外键)链接。我希望用户被链接而不必选择。下面是我的模型。所以我想把每个帖子链接到一个特定的检查文件。在
^{pr2}$表单是一个简单的模板:
<form class = "form_horizontal" action = "" method = "post">
{% csrf_token %}
{{form.as_p}}
<button type="submit">Submit</button>
</form>
我认为您需要重写
post
视图中的post
方法:主题外:python中的类名通常在CamelCase中以单数形式调用。所以}
class Post(models.Model)
和{相关问题 更多 >
编程相关推荐