Each model has a meta attribute with a list of fields on it; for a
Photo model, for example, you can use Photo._meta.fields.

This means you could do something (at least in the shell) like:

>>> fields = Photo._meta.fields
>>> photo = Photo.objects.latest()
>>> for field in fields:
...     print '%s: %s' % (field.name,
photo.__getattribute__(field.name))

and get a list of all of photo's field names and values. I'm not sure
how best to do this in a template yet, but it shouldn't be that hard
to figure out.

HTH,
Justin

On Jul 17, 4:11 am, Kenneth Gonsalves <law...@au-kbc.org> wrote:
> On Saturday 17 July 2010 12:30:19 david wrote:
>
> >   Just learning about Django, and I would like to know what the best
> > way to generate a table from my data, similar to what the "admin" app
> > does. I attempted to dig into the source of the admin app, but I was
> > unable to achieve much.
>
> > I don't want to create a template that has for loops that list all of
> > my data model's fields, instead, i want it to somehow generate all of
> > the public fields in my data model.
>
> best way is to create a template that has for loops that list all of your data
> model's fields - that is what django is for.
> --
> Regards
> Kenneth Gonsalves
> Senior Associate
> NRC-FOSS at AU-KBC

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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