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 --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---