how to list fields in a model?

98 views
Skip to first unread message

hotani

unread,
Jun 20, 2006, 2:12:11 AM6/20/06
to Django users
According to the docs, this should return a dictionary:

model.objects.filter(id=5).values()

However, none of the normal dictionary methods work on it, like say
"keys()."

Basically I'd like to grab an entire object and convert it to a
dictionary so I can work with it, is this possible?

Malcolm Tredinnick

unread,
Jun 20, 2006, 2:25:48 AM6/20/06
to django...@googlegroups.com
On Mon, 2006-06-19 at 23:12 -0700, hotani wrote:
> According to the docs, this should return a dictionary:
>
> model.objects.filter(id=5).values()

Not quite: it returns something that acts like a list of dictionaries,
since there is no guarantee that your QuerySet will always contain a
single object.

> However, none of the normal dictionary methods work on it, like say
> "keys()."

In light of the above, try model.objects.filter(id=5).values()[0].keys()

Best wishes,
Malcolm

Reply all
Reply to author
Forward
0 new messages