Hi Mario, I do not think that is possible with the builtin generic views.
I have created my own set of 'generic' views, one of which is also an object_display. You pass it a form definition (based on my displaymodelform class), which gets instantiated with the display_only=True parameter. Something like this (I left out some stuff to make it more readable, I put in a lot of personal extras in there). def object_display(request, Model=None, object=None, object_id=None, Form=None, extra_context={}, template="crud/display.html"): "Display single object" if not Model: raise ImproperlyConfigured, 'object_display requires a Model' if not object: object = get_object_or_404(Model, pk=object_id) ec = {'object': object} if Form: form = Form(instance=object, display_only = True) ec['form'] = form ec.update(extra_context) return render_to_response(template, ec, RequestContext(request)) You also need a template that has {{ form }} in a table definition (you can leave out the <form> tags). To call it, I always use wrapper functions in views.py, because I find that a lot more readable (and often I need to define a lot of extra context). Koen On 27 aug, 18:17, "Mario Hozano" <[EMAIL PROTECTED]> wrote: > 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 -~----------~----~----~----~------~----~------~--~---