Friday, August 6, 2010

Re: queryset field order

okay that's great but is there a way to get the list of fields from a
model instance instead of from the Model class itself?
My thought is that if I pass in the list of model instance into the
template, the order should be still there. so why pass in another
variable which contains the model fields.


On Aug 6, 11:04 am, Alec Shaner <asha...@chumpland.org> wrote:
> You can't use a dictionary if you expect a certain order of key/value pairs.
>
> Given model A you could get a list of field objects in the same order (I
> think) as defined in the model class
>
> A._meta.fields
>
> At least with that information you could programatically produce a list of
> data in matching order with a little code.
>
> On Fri, Aug 6, 2010 at 1:34 PM, owidjaya <owidj...@gmail.com> 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?
>
> > 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.
>
> > --
> > You received this message because you are subscribed to the Google Groups
> > "Django users" group.
> > To post to this group, send email to django-users@googlegroups.com.
> > To unsubscribe from this group, send email to
> > django-users+unsubscribe@googlegroups.com<django-users%2Bunsubscribe@googlegroups.com>
> > .
> > For more options, visit this group at
> >http://groups.google.com/group/django-users?hl=en.
>
>

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to django-users+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

No comments:

Post a Comment