title: iterate json object multiple times in python/Django
body: <p>I am using jquery to loop through json object... But some how it doesn't seem to work...</p>
  
  <p>Here is my code,</p>
  
  <pre><code>$.ajax({
          type: "GET",  
          url: "/users/",  
       // data: "page="+pageNum,  
          async: false,  
          dataType: 'json',  
          success: function(data){  
  //alert("OK AJAX");
             $("#search_btn").remove();
             $('#btnadduser').css('visibility','visible');
  
  $.each(data, function() {
    $.each(this, function(k, v) {
      /// iterate through the objects
              $("#nbody").html("&lt;tr style='background-color:#FFFFFF; font-size:14px;'&gt;             &lt;td&gt;"+data.f.user4.first_name+"&lt;/td&gt; &lt;td&gt;"+data.f.user4.last_name+"&lt;/td&gt;&lt;td&gt;"+data.f.user4.username+"&lt;/td&gt; &lt;td&gt;"+data.f.user4.email+"&lt;/td&gt; &lt;td&gt;"+data.f.user4.username+"&lt;/td&gt; &lt;td&gt;");
                });
             });
          }
      });
  </code></pre>
  
  <p>when i print the json object in terminal, here is what I get.</p>
  
  <pre><code>{"f": 
       {"user4": {"username": "user4", "first_name": "Alex", "last_name": "kasina", "is_active": true, "email": "alexkasina@gmail.com"},     
        "user5": {"username": "user5", "first_name": "", "last_name": "", "is_active": false, "email": "", }, "user2": {"username":      "user2", "first_name": "", "last_name": "", "is_active": true, "email": ""}, 
        "user3": {"username": "user3", "first_name": "", "last_name": "", "is_active": true, "email": ""}, 
        "user1": {"username": "user1", "first_name": "", "last_name": "", "is_active": true, "email": ""}, 
        "lexx": {"username": "lexx", "first_name": "", "last_name": "", "is_active": true, "email": "tas.ss@df.dc"}}}
  </code></pre>
  
  <p>I want to iterate through each user setting their first_name, last_name, user_name,...
  Some help please?</p>
  
  <p>The view </p>
  
  <pre><code>@login_required
  def users(request):
      from django.core.serializers.json import DjangoJSONEncoder
      from django.forms.models import model_to_dict
  
      html = User.objects.all()
      f = {}                # initialise the output
      username = 'username'  # one of the fields from myModel
      [f.update({x[username]: x}) for x in [model_to_dict(y) for y in html]]
      result = simplejson.dumps({"f" : f}, cls=DjangoJSONEncoder)
      print result#To see the json object
  return HttpResponse(result)  
  </code></pre>