Change keys in values dictionary.

37 views
Skip to first unread message

Lee Hinde

unread,
Jan 2, 2015, 8:35:42 PM1/2/15
to django...@googlegroups.com
If I do a query:

messages = Recipient.objects.filter(user__system_id=user_id).values("message__id","message__subject")

and then

{"data":list(messages)}

jsonify it, I end up with:

  "data" : [
    {
      "message__id" : "2f24d132-4321-4d63-868a-21de6fbc0d44",
      "message__subject" : "And look, a new subject."
    }
  ],

Let's assume there are lots of messages.

What's the best way rename the keys? I.e, I'd like "message__id" to be "id".


Kristofer Pettijohn

unread,
Jan 3, 2015, 11:31:37 AM1/3/15
to django...@googlegroups.com
This is a feature request that didn't make it into 1.7: https://code.djangoproject.com/ticket/16735



From: "Lee Hinde" <leeh...@gmail.com>
To: django...@googlegroups.com
Sent: Friday, January 2, 2015 7:34:59 PM
Subject: Change keys in values dictionary.

--
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...@googlegroups.com.
To post to this group, send email to django...@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/CA%2BePoMwXBvBC2tLTY1mCWyNcJgYe6v1ybpRd16qhRYwJ8Ta%2Bcg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Collin Anderson

unread,
Jan 4, 2015, 2:50:12 PM1/4/15
to django...@googlegroups.com
Hi,

Why not query it directly from Message?

Message.objects.filter(recipient__user__system_id=user_id).values('id', 'subject')

Collin

Lee Hinde

unread,
Jan 5, 2015, 12:37:12 PM1/5/15
to django...@googlegroups.com
That example was just showing the part of the values 'grab' that was a problem; in real life I'm getting data from Recipient as well.
Reply all
Reply to author
Forward
0 new messages