title: Django comparing model instances for equality
body: <p>I understand that, with a singleton situation, you can perform such an operation as:</p>
  
  <pre><code>spam == eggs
  </code></pre>
  
  <p>and if <code>spam</code> and <code>eggs</code> are instances of the same class with all the same attribute values, it will return <code>True</code>.  In a Django model, this is natural because two separate instances of a model won't ever be the same unless they have the same <code>.pk</code> value.</p>
  
  <p>The problem with this is that if a reference to an instance has attributes that have been updated by middleware somewhere along the way and it hasn't been saved, and you're trying to it to another variable holding a reference to an instance of the same model, it will return <code>False</code> of course because they have different values for some of the attributes. Obviously, I don't need something like a <a href="https://stackoverflow.com/questions/31875/">singleton</a>, but I'm wondering if there some official Djangonic (ha, a new word) method for checking this, or if I should simply check that the <code>.pk</code> value is the same, by running:</p>
  
  <pre><code>spam.pk == eggs.pk
  </code></pre>
  
  <p>I'm sorry if this was a huge waste of time, but it just seems like there might be a method for doing this and something I'm missing that I'll regret down the road if I don't find it.</p>
  
  <h2>UPDATE (02-27-2015)</h2>
  
  <p>You should disregard the first part of this question since you shouldn't compare singletons with <code>==</code>, but rather with <code>is</code>. Singletons really have nothing to do with this question.</p>