在object_detail中使用表单 [英] Using form in object_detail

查看:126
本文介绍了在object_detail中使用表单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这样的感觉。 (但我是新的。)通用视图object_detail使用查询集和id字段进行调用。当object_detail渲染模板时,它将使用template_object_name完成。当我编写模板时,我使用template_object_name并可以显示所有的字段。好的,这很好,但是我有一个FormForm的形式。



那么如何让窗体显示出来?我已经环顾四周了。我尝试将表单传递给extra_context,以便表单可以接受用于呈现模板的对象中的数据,但不能执行。



解决方法只是写一个看法。 object_detail的问题是,通过指定的id拉出行的SQL在object_detail内完成,然后对象进入视图。如果我有兴趣使用我使用ModelForm创建的表单,那么我想设置一个form = mymodelForm(object),并将表单传递给模板进行渲染。另一种提出问题的方法是在object_detail中的钩子在哪里指定什么样的对象被指定?

解决方案

答案是可在使用基于类的通用视图DetailView与ModelForm显示错误 - 如何继续?



感谢大家。对相关问题的评论让我得出结论。没有你没有做到这一点!


This has me stumped. (But I'm new at this.) The generic view object_detail is called with a queryset and the id field of interest. When object_detail then renders the template it is done with the template_object_name. When I write the template I use the template_object_name and can display all the fields. OK, that's nice, but I have a form I made with ModelForm.

So how do I get the form to show up? I've looked around for this. I tried passing the form in extra_context so that the form could accept the data in the object that is used to render the template, but no go.

The workaround is just writing a view. The problem with object_detail is that the SQL that pull out the row by specified id is done inside object_detail and then the object goes to the view. If I'm interested in using the form that I created with ModelForm then I want to set a form=mymodelForm(object) and pass form to the template for rendering. Another way to ask my question is where is the hook in object_detail that specifies what kind of object is specified?

解决方案

The answer is available on Using class based generic view DetailView with a ModelForm reveals a bug - how to proceed?

Thanks to everyone. The comments to the related questions allowed me to figure this out. Couldn't have done this without you!

这篇关于在object_detail中使用表单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆