title: Issue using fixtures in tests with Django DirtyFields
body: <p>Is there a known issue when using fixtures in tests if you are implementing Django DirtyFields?</p>
  
  <p>We use <code>django_nose</code>'s <code>NoseTestSuiteRunner</code> with fixtures and coverage.  I was going to try implementing <code>django-dirtyfields</code> to do some custom <code>post_save()</code> activities.  The only change I made was the following:</p>
  
  <pre><code>from dirtyfields import DirtyFieldsMixin
  
  
  class BaseModel(DirtyFieldsMixin, models.Model):
      """
      Base model
      """
      class Meta:
          abstract = True
  </code></pre>
  
  <p>We use this <code>BaseModel</code> to extend most of our other models.  Adding the <code>DirtyFieldsMixin</code> causes our tests to die with the following repeated error:</p>
  
  <pre><code>Problem installing fixture '/home/ricomoss/workspace/project/settings/../apps/contracts/fixtures/test_contracts_data.json': Traceback (most recent call last):
    File "/home/ricomoss/.virtualenvs/project/local/lib/python2.7/site-packages/django/core/management/commands/loaddata.py", line 193, in handle
      for obj in objects:
    File "/home/ricomoss/.virtualenvs/project/local/lib/python2.7/site-packages/django/core/serializers/json.py", line 47, in Deserializer
      raise DeserializationError(e)
  DeserializationError: Field matching query does not exist.
  </code></pre>
  
  <p>From what I can tell this error occurs whenever a fixture is trying to load.  Any thoughts?  <code>DirtyFieldsMixin</code> does not include any new fields (let alone required ones) that would cause my fixtures to need to be updated.</p>
  
  <p>EDIT 1:
  It appears my problem is directly related to the <a href="https://stackoverflow.com/questions/3499791/how-do-i-prevent-fixtures-from-conflicting-with-django-post-save-signal-code">fixtures/signal</a> problem in Django.  If we look at the <code>DirtyFieldsMixin</code> definition we can see immediately where the problem lies (I've verified this):</p>
  
  <pre><code>class DirtyFieldsMixin(object):
      def __init__(self, *args, **kwargs):
          super(DirtyFieldsMixin, self).__init__(*args, **kwargs)
          post_save.connect(
              self._reset_state, sender=self.__class__,
              dispatch_uid='{}-DirtyFieldsMixin-sweeper'.format(
                  self.__class__.__name__))
          self._reset_state()
  
      def _reset_state(self, *args, **kwargs):
          self._original_state = self._as_dict()
  
      def _as_dict(self):
          return dict([(f.name, getattr(self, f.name)) for f in
                       self._meta.local_fields if not f.rel])
  
      def get_dirty_fields(self):
          new_state = self._as_dict()
          return dict([(key, value) for key, value in
                       self._original_state.iteritems()
                       if value != new_state[key]])
  
      def is_dirty(self):
          # in order to be dirty we need to have been saved at least once, so we
          # check for a primary key and we need our dirty fields to not be empty
          if not self.pk:
              return True
          return {} != self.get_dirty_fields()
  </code></pre>
  
  <p>Specifically,</p>
  
  <pre><code>post_save.connect(self._reset_state, sender=self.__class__,
                    dispatch_uid='{}-DirtyFieldsMixin-sweeper'.format(
                    self.__class__.__name__))
  </code></pre>
  
  <p>I tried creating a decorator as per a <a href="https://code.djangoproject.com/ticket/8399#comment:7" rel="nofollow noreferrer">solution</a> given.  I am either implementing the decorator wrong or it doesn't work for this situation.  I'm a little confused about it's use in this situation.</p>
  
  <p>Would I put the decorator on the <code>__init__</code>:</p>
  
  <pre><code>@utils.disable_for_loaddata
  def __init__(self, *args, **kwargs):
      super(DirtyFieldsMixin, self).__init__(*args, **kwargs)
      post_save.connect(
          self._reset_state, sender=self.__class__,
          dispatch_uid='{}-DirtyFieldsMixin-sweeper'.format(
              self.__class__.__name__))
      self._reset_state()
  </code></pre>
  
  <p>I still get a failure in this case.  Any suggestions?</p>
  
  <p>EDIT 2:
  I've also tried adding the decorator to the <code>_reset_state</code> method.  This does not work either.</p>
  
  <pre><code>@utils.disable_for_loaddata
  def _reset_state(self, *args, **kwargs):
      self._original_state = self._as_dict()
  </code></pre>
  
  <p>EDIT 3:
  I think I'm making progress.  I moved the <code>inspect.stack()</code> portion of the decorator into the <code>__init__</code> directly (just above the <code>post_save</code> call).</p>
  
  <p>I'm getting other activity, although my test suite still hasn't run correctly yet.  I'm no longer getting the loaddata error.</p>
  
  <pre><code>def __init__(self, *args, **kwargs):
      super(DirtyFieldsMixin, self).__init__(*args, **kwargs)
  
      import inspect
      for fr in inspect.stack():
          if inspect.getmodulename(fr[1]) == 'loaddata':
              return
      post_save.connect(
          self._reset_state, sender=self.__class__,
          dispatch_uid='{}-DirtyFieldsMixin-sweeper'.format(
              self.__class__.__name__))
      self._reset_state()
  </code></pre>
  
  <p>EDIT 4:
  I've decided that I'm going to write my own mixin for this process.  I don't believe I need to use a signal for my purposes.  As a result I will be overriding the <code>save()</code> method and handling this in a special way.</p>