title: Set the maximum recursion depth while serializing a Django model with Foreign key to JSON
body: <p>I have a Django model created for Google's App Engine,</p>
  
  <pre><code>Model A():
    propA = ReferenceProperty(B)
  
  Model B():
    propB = ReferenceProperty(C)
  
  Model C():
    propC = ReferenceProperty(B)
  </code></pre>
  
  <p>I have written custom Django serializer which will fetch the data for the ReferenceProperty(s) and serialize that along the initial model.</p>
  
  <p>The problem occurs when I try to serialize an instance of <strong>Model A</strong>. My custom serializer will try to get <strong>propA</strong>, which contains a reference to <strong>Model C</strong> so the serializer will fetch <strong>Model C</strong>, which contains a reference to <strong>Model B</strong> and the recursion goes on and on. Is there any way to stop the recursion after a depth of say 2??</p>
  
  <p>My serializer is a customized version of <a href="http://code.google.com/p/dojango/source/browse/trunk/dojango/util/__init__.py#97" rel="nofollow noreferrer" title="this serializer.">link text</a></p>
  
  <p><strong>P.S:</strong> I am willing to publish my code if that seems to needed. I have not currently attached the code since I am not at my development machine.</p>
  
  <p>Thanks,<br/>
  Arun Shanker Prasad.</p>