Skip to content

Commit 9333e2d

Browse files
author
Ross Mechanic
committed
Fixed issue where build would break on django 1.6 due to different method of importing models
1 parent 7f571c7 commit 9333e2d

File tree

3 files changed

+31
-9
lines changed

3 files changed

+31
-9
lines changed
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
from __future__ import unicode_literals
2+
3+
from django.db import models
4+
from simple_history.models import HistoricalRecords
5+
6+
7+
class AbstractExternal(models.Model):
8+
history = HistoricalRecords(inherit=True)
9+
10+
class Meta:
11+
abstract = True
12+
app_label = 'external'

simple_history/tests/external/models/model2.py

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,3 @@ class ExternalModel2(models.Model):
1010

1111
class Meta:
1212
app_label = 'external'
13-
14-
15-
class AbstractExternal(models.Model):
16-
history = HistoricalRecords(inherit=True)
17-
18-
class Meta:
19-
abstract = True
20-
app_label = 'external'

simple_history/tests/models.py

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,30 @@
11
from __future__ import unicode_literals
22

33
from django.db import models
4+
from django import VERSION
45

56
from simple_history.models import HistoricalRecords
67
from simple_history import register
78

89
from .custom_user.models import CustomUser as User
9-
from .external.models.model2 import AbstractExternal
10+
11+
try:
12+
from django.apps import apps
13+
except ImportError: # Django < 1.7
14+
from django.db.models import get_model
15+
else:
16+
get_model = apps.get_model
17+
18+
# 1.6 has different way of importing models
19+
if VERSION[:3] >= (1, 7, 0):
20+
from .external.models.model1 import AbstractExternal
21+
else:
22+
class AbstractExternal(models.Model):
23+
history = HistoricalRecords(inherit=True)
24+
25+
class Meta:
26+
abstract = True
27+
app_label = 'external'
1028

1129

1230
class Poll(models.Model):

0 commit comments

Comments
 (0)