title: Is there a way to elegantly "swap" rows in all foreign key and many to many fields in django?
body: <p>I have a class let's call it <code>Entity</code> it's a container for a label and a type and then I have many other models like <code>Store</code>, <code>Purchase</code>... And they have a relationship like so:</p>
  
  <pre><code>class Store(Model):
   store_name = TextField()
   entities = ManyToManyField(Entity)
  
  class Purchase(Model):
   datetime = DatetimeField(auto=True)
   entity = ForeignKeyField(Entity)
  </code></pre>
  
  <p>In this case, say that I have an entity that I end up wanting to "swap" for instance, at some time I had "CocaCola" and then I have "Coca Cola", the user decides hey these two are the same, let's "merge them", effectively what I need to do is delete CocaCola or Coca Cola and swap all the keys out</p>
  
  <p>so....</p>
  
  <pre><code>for p in Purchase.objects.filter(entity=cocacola_entity):
   p.entity = coca_cola_entity
   p.save()
  for s in Purchase.objects.filter(entities=cocacola_entity):
   s.entities.remove(cocacola_entity)
   s.entities.add(coca_cola_entity)
   s.save()
  cocacola_entity.delete()
  </code></pre>
  
  <p>Is there a better way to handle this in a global context? I.e. "Django magically fetch me EVERYTHING with this row as a foreign key and swap it with the other one)</p>