Saturday, June 25, 2011

can i control select column order in a queryset?

Hi Folks:

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?

Regards,

Joe


--
You received this message because you are subscribed to the Google Groups "Django users" group.
To view this discussion on the web visit https://groups.google.com/d/msg/django-users/-/sPhNTN8fqv0J.
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.

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate