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

Reply via email to