The reason you are getting a dictionary in return is because the call to 
values() returns a ValueQuerySet, which is an iterable of dictionaries (
https://docs.djangoproject.com/en/dev/ref/models/querysets/#values)
In order to get a list of tee colors (eg ['Blue',Green','Red']) you should 
use a value_list(). values_list usually returns a list of tuple, but if you 
are only asking for a single field you can give it the flat flag, which 
flattens the tuples into just the field value. (
https://docs.djangoproject.com/en/dev/ref/models/querysets/#values-list)

Taken all together, your query should be:
teecolors = 
GolfCourseTees.objects.filter(Course_Name=course).values_list('Tee_Color', 
flat=True)

Kirby

On Saturday, May 3, 2014 7:47:07 PM UTC-5, Brendan Edwards wrote:
>
> Hi,
>  
> I have just started learning Django (been flip flopping between meteor and 
> django, cant decide which to use..) and I am fairly new to web development 
> in general.
>  
> Basically, I have a query where I am using the code "teecolor = 
> GolfCourseTees.objects.values('Tee_Color').filter(Course_Name=course)" but 
> I want to take the value retrieved form this and use it to make another 
> query before loading the template. When I set color1= teecolor[0] color 1 
> will show as: {'Tee_Color': u'Blue'}, and I am unsure why this happens. I 
> want to retrieve only the value "blue" in this case.
>  
> The reason for this is each course has usualy 4-5 tee colors. therefore I 
> will have color1 = teecolor[0], color 2 = teecolor[1] etc.. so that I can 
> insert that into a second query. To do that these values need to be "blue" 
> "black" etc
>  
> Questions:
>  
> 1) What is the data "{'Tee_Color': u'Blue'}" output "{'Tee_Color': 
> u'Blue'}" called and why does it display like this (I would like to 
> understand and not just insert a given line of code)? I have read the 
> documentation and I am still confused on this. 
> 2) How can I retrieve blue from {'Tee_Color': u'Blue'}? (example code 
> would be helpful)
> Brendan
>  
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/5dc76b9c-c4c0-4637-b390-572aabea1a3e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to