> To Olivier: Iterating through javascript like that is possible, but it > poses a disadvantage in that I cannot access the data's related object > (e.g. ForeignKey relationships). > For example I can do data[0].fields.user and I'd get "3" as a > response, but I cannot do data[0].fields.user.username, where user is > a foreignkey. Whereas in Django I can do something like this: > manager.user.username and I'd get the user name.
That's the reason you may want to build a custom JSON dict and use simplejson.dumps(). Something like: orders_qs = Order.objects.all() orders = [] for order in order_qs: # stuff all the fields and foreign key fields you want to use here. item = [order.foo, order.spam, order.user.username] orders.append(item) output = {"orders" : orders} return HTTPResponse(simplejson.dumps(output), mimetype = "application/ javascript") and in javascript var form_data = { url: "/ajax_form_test/", handleAs: "json", load: function(data){ for (i = 0, i < data.orders.length, i ++) { // Do something } }, --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---