44import warnings
55from datetime import datetime , timedelta
66
7- import django
7+ from django . apps import apps
88from django .contrib .auth import get_user_model
99from django .core .files .base import ContentFile
1010from django .db import models
1111from django .db .models .fields .proxy import OrderWrt
1212from django .test import TestCase
13+
1314from simple_history .models import HistoricalRecords , convert_auto_field
1415from simple_history .utils import update_change_reason
15-
1616from ..external .models import ExternalModel2 , ExternalModel4
1717from ..models import (AbstractBase , AdminProfile , Book , Bookcase , Choice , City ,
18- ConcreteAttr , ConcreteUtil , Contact , ContactRegister ,
18+ ConcreteAttr , ConcreteExternal , ConcreteUtil , Contact , ContactRegister ,
1919 Country , Document , Employee , ExternalModel1 ,
2020 ExternalModel3 , FileModel , HistoricalChoice ,
2121 HistoricalCustomFKError , HistoricalPoll , HistoricalState ,
2222 Library , MultiOneToOne , Person , Poll , PollInfo ,
2323 PollWithExcludeFields , Province , Restaurant , SelfFK ,
2424 Series , SeriesWork , State , Temperature ,
2525 UnicodeVerboseName , WaterLevel )
26- from django .apps import apps
2726
2827get_model = apps .get_model
2928User = get_user_model ()
@@ -345,7 +344,7 @@ def test_create_history_model_with_one_to_one_field_to_integer_field(self):
345344 records = HistoricalRecords ()
346345 records .module = AdminProfile .__module__
347346 try :
348- records .create_history_model (AdminProfile )
347+ records .create_history_model (AdminProfile , False )
349348 except :
350349 self .fail ("SimpleHistory should handle foreign keys to one to one"
351350 "fields to integer fields without throwing an exception" )
@@ -354,7 +353,7 @@ def test_create_history_model_with_one_to_one_field_to_char_field(self):
354353 records = HistoricalRecords ()
355354 records .module = Bookcase .__module__
356355 try :
357- records .create_history_model (Bookcase )
356+ records .create_history_model (Bookcase , False )
358357 except :
359358 self .fail ("SimpleHistory should handle foreign keys to one to one"
360359 "fields to char fields without throwing an exception." )
@@ -363,7 +362,7 @@ def test_create_history_model_with_multiple_one_to_ones(self):
363362 records = HistoricalRecords ()
364363 records .module = MultiOneToOne .__module__
365364 try :
366- records .create_history_model (MultiOneToOne )
365+ records .create_history_model (MultiOneToOne , False )
367366 except :
368367 self .fail ("SimpleHistory should handle foreign keys to one to one"
369368 "fields to one to one fields without throwing an "
@@ -396,6 +395,10 @@ def test_register_app_label(self):
396395 'external_externalmodel4' )
397396 self .assertEqual (self .get_table_name (ExternalModel4 .histories ),
398397 'tests_historicalexternalmodel4' )
398+ self .assertEqual (self .get_table_name (ConcreteExternal .objects ),
399+ 'tests_concreteexternal' )
400+ self .assertEqual (self .get_table_name (ConcreteExternal .history ),
401+ 'tests_historicalconcreteexternal' )
399402
400403 def test_get_model (self ):
401404 self .assertEqual (get_model ('external' , 'ExternalModel1' ),
@@ -418,6 +421,13 @@ def test_get_model(self):
418421 self .assertEqual (get_model ('tests' , 'HistoricalExternalModel4' ),
419422 ExternalModel4 .histories .model )
420423
424+ # Test that historical model is defined within app of concrete
425+ # model rather than abstract base model
426+ self .assertEqual (get_model ('tests' , 'ConcreteExternal' ),
427+ ConcreteExternal )
428+ self .assertEqual (get_model ('tests' , 'HistoricalConcreteExternal' ),
429+ ConcreteExternal .history .model )
430+
421431
422432class HistoryManagerTest (TestCase ):
423433 def test_most_recent (self ):
0 commit comments