-
-
Notifications
You must be signed in to change notification settings - Fork 472
Commit
register() will place records under given app. Meta app_label will place both model / records under given app.
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -44,6 +44,14 @@ def create_history_model(self, model): | |
""" | ||
attrs = {'__module__': self.module} | ||
|
||
app_module = models.get_app(model._meta.app_label) | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
dnozay
Author
Contributor
|
||
if model.__module__ != self.module: | ||
This comment has been minimized.
Sorry, something went wrong.
treyhunner
Member
|
||
# registered under different app | ||
attrs['__module__'] = self.module | ||
elif app_module.__name__ != self.module: | ||
# has meta options with app_label | ||
attrs['__module__'] = app_module.__name__ | ||
|
||
fields = self.copy_fields(model) | ||
attrs.update(fields) | ||
attrs.update(self.get_extra_fields(model, fields)) | ||
|
@@ -135,9 +143,10 @@ def get_meta_options(self, model): | |
Returns a dictionary of fields that will be added to | ||
the Meta inner class of the historical record model. | ||
""" | ||
return { | ||
options = { | ||
'ordering': ('-history_date', '-history_id'), | ||
} | ||
return options | ||
|
||
def post_save(self, instance, created, **kwargs): | ||
if not created and hasattr(instance, 'skip_history_when_saving'): | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
|
||
from django.db import models | ||
from simple_history.models import HistoricalRecords | ||
from simple_history import register | ||
|
||
class ExternalModel2(models.Model): | ||
name = models.CharField(max_length=100) | ||
history = HistoricalRecords() | ||
|
||
class ExternalModel4(models.Model): | ||
name = models.CharField(max_length=100) | ||
|
||
register(ExternalModel4, app='simple_history.tests', | ||
manager_name='histories') |
This line is causing import errors when running tests in my project that uses django-simple-history.
This is run when the model classes are being created so many Django imports cannot be reliably used. I'm not sure why this one is causing my project to fail, but we'll need to find a different way to do this.