title: Get Django to include the model id in the string representation of all model instances for debugging
body: <p>Django's model <code>Model</code> class defines a <code>__repr__</code> method that combines the model class name with the string representation of the instance, so that a typical object will show up in the shell or in debugging tools in the following format:</p>
  
  <pre><code>&lt;MyClass: string description of instance&gt;
  </code></pre>
  
  <p>What I want is for all of my objects instances to show up with their ids in their <code>__repr__</code>, e.g.</p>
  
  <pre><code>&lt;MyClass 123: string description of instance&gt;
  </code></pre>
  
  <p>This is for debugging convenience.</p>
  
  <p>Now, it would be easy enough (in principle) to override my <code>__unicode__</code> methods (which generate the string description of instances) to include the ids, or for that matter to override my <code>__repr__</code> methods (or to have all my model classes derive from a base class that does so). </p>
  
  <p>However, I'm working with an existing code base and want to avoid changing all the existing model class definitions for this. The quick-and-dirty way to change things is to edit the source code for <code>__repr__</code> in Django's Model class. But that creates deployment issues as my project always deploys third-party libraries like Django from pip. </p>
  
  <p>So: how can I get Django to include the id in the repr for all object instances without either changing the Django source code or my project model class definitions? </p>
  
  <p>NOTE: I'm thinking some kind of monkey patch to <code>Model.__repr__</code> should do the trick, but I'm not sure if that would work and if so where in my Django project to do it. </p>