Great!! I think that the _meta attribute will be enough. I think that if I define a method on the base model of all my models something like get_fields() it could then return a list of the fields by accessing self._meta.fields, and this get_fields should be accessible from templates,shouldn't it?.
Thanks for your help :-) bruno desthuilliers wrote: > On 8 jan, 16:22, Matias Surdi <matiassu...@gmail.com> wrote: >> Is there any way to iterate over all the fields in a model instance on a >> template? > > Not directly. The fields names are accessible thru the > model_instance._meta attribute, and you cannot access '_protected' > attributes in a template. > >> I'd like to have a "default" template which iterates over whatever model >> yo give it and prints all its field on a table. > > You'll have to write a (simple) view that returns the model instance's > fields names and values as context. But that's mostly trivial once you > know how to get field names and values from an instance (which has > already been explained here - but feel free to ask if you fail to find > the relevant posts). > > > > > --~--~---------~--~----~------------~-------~--~----~ 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 django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~----------~----~----~----~------~----~------~--~---