Monday, August 10, 2015

Generic forms (ModelForm) provide HTML for a form! Can generic views (DetailView) do same?

This has bamboozled me for a while. I Have a wonderful little test app I'm playing with which lists objects (ListView) and next to each object puts an edit and view link. Sort of like:
  • [view] [edit] Object 1
  • [view] [edit] Object 2
  • [view] [edit] Object 3

The ListView works like a dream. The ModelForm works a dream and on the edit link I can simply display the form by including {{ form }} in a generic template. What a beautifully fficient generic way of rendering quick test forms and such. Love it.


Now I want to do same with a DetailView, i.e. render a page that just shows me Object 1 say much like my ModelForm does but not as a form as a readonly display, using labels not fields:

The form say provides:

<tr><th><label for="id_prop1">Label 1:</label></th><td><input id="id_prop1" ... /></td></tr>
<tr><th><label for="id_prop2">Label 2:</label></th><td><input id="id_prop2" ... /></td></tr>
<tr><th><label for="id_prop3">Label 3:</label></th><td><input id="id_prop3" ... /></td></tr>
<tr><th><label for="id_prop4">Label 4:</label></th><td><input id="id_prop4" ... /></td></tr>



Can DetailView not provide me with something similar, like:

<tr><th>Label 1:</th><td>Value 1</td></tr>
<tr><th>Label 2:</th><td>Value 2</td></tr>
<tr><th>Label 3:</th><td>Value 3</td></tr>
<tr><th>Label 4:</th><td>Value 4</td></tr>

I find it hard to believe not, but danged if I can find it!

An odd inconsistency if so. Do I really have to derive a class DetailViewWithHTML from it and write my own wrappers?

Regards,

Bernd.


--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/bd44bdce-0031-490e-897a-d62e0c7163d8%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment