Using form in object_detail

It puzzled me. (But I'm new to this.) The general view of object_detail is called with the request and the identifier field. When object_detail then displays the template, this is done with the name template_object_name. When I write a template, I use template_object_name and can display all fields. Ok, that’s good, but I have a form that I created with ModelForm.

So how do I get the form? I looked around. I tried passing the form to extra_context so that the form can receive data in the object that is used to render the template, but not go.

The workaround is just a view entry. The problem with object_detail is that the SQL that pulls the string at the specified id is executed inside object_detail, and then the object jumps to the view. If I'm interested in using the form I created with ModelForm, then I want to set the form = mymodelForm (object) and pass the form to the template for rendering. Another way to ask the question is: where is the hook_ object, indicating which object is listed?

0
source share
1 answer

The answer is available on Using a generic DetailView with ModelForm shows an error - how to proceed?

Thanks to everyone. Comments on related issues made me understand this. Could do it without you!

0
source

Source: https://habr.com/ru/post/891913/


All Articles