Hi Koen, I think your code snippet will work fine in my application too. But, how instantiate the DisplayModelForm directly in my urls.py showed below?
(r'^core/user/show/(?P<object_id>\d+)/$', 'object_detail', dict(queryset=User.objects.all(), template_name="baseshow.html", extra_context={'model_entity':'user'})) Should I use the 'django.views.generic.create_update.create_object' view? I want only to use the urls.py without write in views.py to instantiate the form. Is it possible? Thanks. Mario Hozano. On Wed, Aug 27, 2008 at 3:34 AM, koenb <[EMAIL PROTECTED]> wrote: > > Hi Mario, > > a few months ago I posted a snippet on djangosnippets [1] that kind of > does something like this: it takes a form (can be the same one you use > for editing) and displays it as read-only. The disadvantage is it uses > the entire form machinery just to display some values, which is a lot > of overhead, the advantage is I have quick and dirty display of data > without much extra work (I have my own generic view wrapped around > this). > It needs a lot of improvement, but it works ok for me for now. > > Koen > > [1]: http://www.djangosnippets.org/snippets/758/ > > On 26 aug, 20:00, Mario Hozano <[EMAIL PROTECTED]> wrote: > > Hi People. > > > > I am new in Django and I am using the django support to create generic > > views (CRUD) in my app. To handle Create and Show actions, i have > > written 2 main pages with the code snippets described below. > > > > baseform.html > > {% for field in form %} > > <dt>{{ field.label_tag }}{% if field.field.required %}*{% > endif > > %}</dt> > > <dd>{{ field }}</dd> > > {% if field.help_text %}<dd>{{ field.help_text }}</dd>{% > endif %} > > {% if field.errors %}<dd class="myerrors">{{ field.errors > }}</ > > dd>{% endif %} > > {% endfor %} > > > > baseshow.html. > > {% for key, value in object.as_dict.items %} > > <dt>{{ key.capitalize }}</dt> > > <dd>{{ value }}</dd> > > {% endfor %} > > > > These pages are called directly from my urls.py that uses the Generic > > views supported by django. In this sense, the baseform.html can be > > used by all model classes, because the ModelForm handles the > > presentation of each model attribute (excluding id) transparently. > > > > In baseshow.html I need to show the same attributes of a given model > > class, as done in baseform.html. In this case, the attributes > > (excluding id) must be presented in a read-only mode, with html labels > > instead of input widgets. To do it, i've implemented a "as_dict" > > method in each model class. This method only returns the > > "self.__dict__" attribute of the model classes, hence, the private > > attributes cannot be acessed from templates. > > > > The solution presented works, but it is ugly, because the id attribute > > must be verified on template and it needs to adjust the model class to > > work fine. > > > > Does Django offer another way to present the model attributes in a > > Show view? Is it possible to use a ModelForm class to show the > > attribute values in html labels? > > > > Thanks. > > Mario Hozano > > > -- Mário Hozano Lucas de Souza Embedded and Pervasive Computing Laboratory - embedded.ufcg.edu.br Electrical Engineering and Informatics Center - CEEI Federal University of Campina Grande - UFCG - www.ufcg.edu.br PGP: 0xAEA0ACBD --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~----------~----~----~----~------~----~------~--~---