On Sat, Jun 25, 2011 at 6:39 PM, Joe Linoff <jlin...@gmail.com> wrote:

> I am a newbie who is really enjoying Django. It is a great system and has
> really saved me a lot of time but I am having a problem trying to control
> the column order in a queryset.
>
> In SQL my queries would look something like this:
>
>       -- column order #1
>       SELECT 'Third','Second',First' FROM test ORDER BY 'Third' ASC;
>       -- column order #2
>       SELECT 'First','Third','Second' FROM test ORDER BY 'First' ASC;
>
> In Django 1.3 I am doing this:
>
>     # column order #1
>     data =
> test.objects.values('Third','Second','First').order_by('Third').all()
>     data = test.objects.values('Third','Second','First') # tried this as
> well
>
>     # column order #2
>     data =
> test.objects.values('First','Third','Second').order_by('First').all()
>     data = test.objects.values('First','Third','Second') # tried this as
> well
>
> Unfortunately, the columns are always returned in the same order.
>
> What am I doing wrong? I am trying to do something that isn't supported?
>

The calls you are showing returns lists of dictionaries. Dictionaries have
no specified order.

The order_by call you've tried in a couple of places orders the elements in
the lists, based on the values in the specified columns. It has nothing to
do with "column order".

If you describe what you are trying to achieve someone might be able to
help. You should not be caring about "column order" when using Django.

Karen
-- 
http://tracey.org/kmt/

-- 
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+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.

Reply via email to