Skip to content

Commit

Permalink
Merge ccd213d into 866ef4b
Browse files Browse the repository at this point in the history
  • Loading branch information
matklad committed Sep 5, 2013
2 parents 866ef4b + ccd213d commit c7208e9
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 0 deletions.
1 change: 1 addition & 0 deletions simple_history/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,6 @@ def register(model, app=None, manager_name='history'):
records = models.HistoricalRecords()
records.manager_name = manager_name
records.module = app and ("%s.models" % app) or model.__module__
records.add_extra_methods(model)
records.finalize(model)
models.registered_models[model._meta.db_table] = model
2 changes: 2 additions & 0 deletions simple_history/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,9 @@ def contribute_to_class(self, cls, name):
self.manager_name = name
self.module = cls.__module__
models.signals.class_prepared.connect(self.finalize, sender=cls)
self.add_extra_methods(cls)

def add_extra_methods(self, cls):
def save_without_historical_record(self, *args, **kwargs):
"""
Save model without saving a historical record
Expand Down
4 changes: 4 additions & 0 deletions simple_history/tests/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,10 @@ def test_save_without_historical_record(self):
'history_type': "~",
})

def test_save_without_historical_record_for_registered_model(self):
registered_model = ExternalModel3.objects.create(name='registered model')
self.assertTrue(hasattr(registered_model, 'save_without_historical_record'))

def test_save_raises_exception(self):
anthony = Person(name='Anthony Gillard')
with self.assertRaises(RuntimeError):
Expand Down

0 comments on commit c7208e9

Please sign in to comment.