title: How to overriding model save function when using factory boy?
body: <p>I'm using <a href="https://github.com/FactoryBoy/factory_boy" rel="noreferrer">Factory Boy</a> for testing a Django project and I've run into an issue while testing a model for which I've overridden the save method.</p>
  
  <p>The model:</p>
  
  <pre><code>class Profile(models.Model):
  
      active = models.BooleanField()
      user = models.ForeignKey(get_user_model(), on_delete=models.CASCADE,
                               related_name='profiles')
      department = models.ForeignKey(Department, null=True, blank=True)
      category_at_start = models.ForeignKey(Category)
      role = models.ForeignKey(Role)
      series = models.ForeignKey(Series, null=True, blank=True)
      status = models.ForeignKey('Status', Status)
  
      def save(self, *args, **kwargs):
          super(Profile, self).save(*args, **kwargs)
          active_roles = []
          active_status = []
          for profile in Profile.objects.filter(user=self.user):
              if profile.active:
                  active_roles.append(profile.role.code)
                  active_status.append(profile.status.name)
          self.user.current_role = '/'.join(set(active_roles))
          if 'Training' in active_status:
              self.user.current_status = 'Training'
          elif 'Certified' in active_status:
              self.user.current_status = 'Certified'
          else:
              self.user.current_status = '/'.join(set(active_status))
          self.user.save()
          super(Profile, self).save(*args, **kwargs) ### &lt;-- seems to be the issue.
  </code></pre>
  
  <p>The factory:</p>
  
  <pre><code>class ProfileFactory(f.django.DjangoModelFactory):
      class Meta:
          model = models.Profile
  
      active = f.Faker('boolean')
      user = f.SubFactory(UserFactory)
      department = f.SubFactory(DepartmentFactory)
      category_at_start = f.SubFactory(CategoryFactory)
      role = f.SubFactory(RoleFactory)
      series = f.SubFactory(SeriesFactory)
      status = f.SubFactory(StatusFactory)
  </code></pre>
  
  <p>The test:</p>
  
  <pre><code>class ProfileTest(TestCase):
  
      def test_profile_creation(self):
          o = factories.ProfileFactory()
          self.assertTrue(isinstance(o, models.Profile))
  </code></pre>
  
  <p>When I run the tests, I get the following error:</p>
  
  <pre><code>django.db.utils.IntegrityError: UNIQUE constraint failed: simtrack_profile.id
  </code></pre>
  
  <p>If I comment out the last last/second 'super' statement in the Profile save method the tests pass. I wonder if this statement is trying to create the profile again with the same ID? I've tried various things such as specifying in the Meta class django_get_or_create and various hacked versions of overriding the _generation method for the Factory with disconnecting and connecting the post generation save, but I can't get it to work. </p>
  
  <p>In the meantime, I've set the strategy to build but obviously that won't test my save method.</p>
  
  <p>Any help greatly appreciated.</p>
  
  <p>J.</p>