Rick Hurst Web Developer in Bristol, UK

Menu

Get a list of attributes for a django object

For a queryset:

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