Repository: jazzband/django-simple-history

Issue:
skip_history_when_saving does not work as expected
**Describe the bug**
I am trying to avoid writing to history when certain condition is met. I have a base model that looks the following.
```python
class BaseModel(models.Model):
    ...
    history = HistoricalRecords(inherit=True)
    
    def save(self, *, skip_history_when_saving=True, **kwargs):
        if skip_history_when_saving:
            self.skip_history_when_saving = skip_history_when_saving
        super().save(**kwargs)
```
For my models, I am creating it using:
```python
class MyModel(BaseModel):
    ...

my_model = MyModel()
my_model.full_clean()
my_models.save(skip_history_when_saving=True) #expecting only one insertion into the MyModel db but seeing an entry being created for simple history MyModel table as well)
```
`save()` gets called as expected in the base model, at the end of execution, it's still creating an entry in historical table. I can confirm it by looking at the sql query. 


**Expected behavior**
Expecting only the model instance to be created without creating the historical model instance on post creation. 

**Environment (please complete the following information):**
 - Django Simple History Version: [e.g. 3.2.0]
 - Django Version: [e.g. 4.1.7]




Discussion:

Resolving patch:
diff --git a/simple_history/models.py b/simple_history/models.py
--- a/simple_history/models.py
+++ b/simple_history/models.py
@@ -180,9 +180,9 @@ def contribute_to_class(self, cls, name):
     def add_extra_methods(self, cls):
         def save_without_historical_record(self, *args, **kwargs):
             """
-            Save model without saving a historical record
+            Save the model instance without creating a historical record.
 
-            Make sure you know what you're doing before you use this method.
+            Make sure you know what you're doing before using this method.
             """
             self.skip_history_when_saving = True
             try:
@@ -651,8 +651,9 @@ def get_meta_options(self, model):
     def post_save(self, instance, created, using=None, **kwargs):
         if not getattr(settings, "SIMPLE_HISTORY_ENABLED", True):
             return
-        if not created and hasattr(instance, "skip_history_when_saving"):
+        if hasattr(instance, "skip_history_when_saving"):
             return
+
         if not kwargs.get("raw", False):
             self.create_historical_record(instance, created and "+" or "~", using=using)
 


Test patch:
diff --git a/simple_history/tests/tests/test_models.py b/simple_history/tests/tests/test_models.py
--- a/simple_history/tests/tests/test_models.py
+++ b/simple_history/tests/tests/test_models.py
@@ -2424,12 +2424,12 @@ def test_m2m_relation(self):
         self.assertEqual(self.poll.history.all()[0].places.count(), 0)
         self.assertEqual(poll_2.history.all()[0].places.count(), 2)
 
-    def test_skip_history(self):
+    def test_skip_history_when_updating_an_object(self):
         skip_poll = PollWithManyToMany.objects.create(
             question="skip history?", pub_date=today
         )
-        self.assertEqual(self.poll.history.all().count(), 1)
-        self.assertEqual(self.poll.history.all()[0].places.count(), 0)
+        self.assertEqual(skip_poll.history.all().count(), 1)
+        self.assertEqual(skip_poll.history.all()[0].places.count(), 0)
 
         skip_poll.skip_history_when_saving = True
 
@@ -2437,8 +2437,8 @@ def test_skip_history(self):
         skip_poll.save()
         skip_poll.places.add(self.place)
 
-        self.assertEqual(self.poll.history.all().count(), 1)
-        self.assertEqual(self.poll.history.all()[0].places.count(), 0)
+        self.assertEqual(skip_poll.history.all().count(), 1)
+        self.assertEqual(skip_poll.history.all()[0].places.count(), 0)
 
         del skip_poll.skip_history_when_saving
         place_2 = Place.objects.create(name="Place 2")
@@ -2448,6 +2448,18 @@ def test_skip_history(self):
         self.assertEqual(skip_poll.history.all().count(), 2)
         self.assertEqual(skip_poll.history.all()[0].places.count(), 2)
 
+    def test_skip_history_when_creating_an_object(self):
+        initial_poll_count = PollWithManyToMany.objects.count()
+
+        skip_poll = PollWithManyToMany(question="skip history?", pub_date=today)
+        skip_poll.skip_history_when_saving = True
+        skip_poll.save()
+        skip_poll.places.add(self.place)
+
+        self.assertEqual(skip_poll.history.count(), 0)
+        self.assertEqual(PollWithManyToMany.objects.count(), initial_poll_count + 1)
+        self.assertEqual(skip_poll.places.count(), 1)
+
     @override_settings(SIMPLE_HISTORY_ENABLED=False)
     def test_saving_with_disabled_history_doesnt_create_records(self):
         # 1 from `setUp()`