Saturday, January 3, 2015

Re: Change keys in values dictionary.

This is a feature request that didn't make it into 1.7: https://code.djangoproject.com/ticket/16735



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

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".


--
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+unsubscribe@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/CA%2BePoMwXBvBC2tLTY1mCWyNcJgYe6v1ybpRd16qhRYwJ8Ta%2Bcg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment