Using form in object_detail

眉间皱痕 提交于 2019-12-11 17:57:54

问题


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?


回答1:


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!



来源:https://stackoverflow.com/questions/6522808/using-form-in-object-detail

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!