Get a list of attributes for a django object
This post was written 2 years ago.
Mon, 10 Oct 2011
For a queryset:
For a single object instance:-
Also for a single object instance - returns fields and values as a dict
Iterate through the dict like above:
Comments
myobj.objects.filter(foo=bar)
myobj.values()[0].keys()
For a single object instance:-
for field in speaker._meta.fields:
print field.name
Also for a single object instance - returns fields and values as a dict
speaker.__dict__
Iterate through the dict like above:
for k,v in speaker.__dict__.iteritems():
print k,v