On 8/6/2010 1:34 PM, owidjaya wrote: > is there a way that i can get the a list of dictionaries as a result > with the dictionary having the same field order as the table? > What do you regard as the "field order" of the dictionary? If you are talking about the order Python iterates over the field, this is not predictable or controllable: it is an artefact of the dict implementation, whose primary focus is on speed of operation.
But you can get the list of field names from the model using model._meta.get_all_field_names(), create a set of (name, value) tuples with zip() and then iterate over that? http://stackoverflow.com/questions/2170228/django-iterate-over-model-instance-field-names-and-values-in-template might give you some ideas. regards Steve > On Aug 6, 10:18 am, Daniel Roseman <dan...@roseman.org.uk> wrote: >> On Aug 6, 6:08 pm, owidjaya <owidj...@gmail.com> wrote: >> >>> I checked it and the field order still not the same. >>> Just to clarify. I want the to do this A.objects.all().values() >>> and still get the each list in the result to have the same "field >>> order" as the database table defined. >> >> `values()` returns a set of dictionaries. Dictionaries are unordered >> by definition. >> >> `values_list()` returns a set of tuples, which should be in the same >> order as the model definition, however you don't get the fieldnames. >> -- >> DR. > -- I'm no expert. "ex" == "has-been"; "spurt" == "drip under pressure" "expert" == "has-been drip under pressure". -- 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.