But is is simple to convert what you have into what you want:

    l = 
User.objects.filter(username__in=['foo','bar']).values('username', 'email')
    emails = dict([(d['username'], d['email']) for d in l])

It would be a little simpler like this:

    emails = dict([(r.username, r.email) for r in 
User.objects.filter(username__in=['foo','bar'])])

The dict() built-in accepts a number of forms of arguments.  One is a 
list of pairs, each of which becomes a key and value in the resulting 
dictionary.

--Ned.

Malcolm Tredinnick wrote:
> Hi Dirk,
>
> On Sat, 2007-02-10 at 12:02 +0100, Dirk Eschler wrote:
>   
>> Hello,
>>
>> i'm trying to get a dict of emails with usernames as keys.
>>
>> User.objects.filter(username__in=['foo', 'bar']).values('username', 'email')
>>
>> The above returns a list of dicts:
>> [{'username': 'foo', 'email': '[EMAIL PROTECTED]'}, 
>> {'username': 'bar', 'email': '[EMAIL PROTECTED]'}]
>>
>> Is it possible to get a dict like this with Django's db api?:
>> {'foo':'[EMAIL PROTECTED]', 'bar':'[EMAIL PROTECTED]'}
>>     
>
> No, it is not possible to get that sort of dictionary back directly from
> Django.
>
> Regards,
> Malcolm
>
>
>
> >
>
>
>
>   

-- 
Ned Batchelder, http://nedbatchelder.com


--~--~---------~--~----~------------~-------~--~----~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to