@@ -44,9 +44,10 @@ class HistoricalRecords(object):
44
44
thread = threading .local ()
45
45
46
46
def __init__ (self , verbose_name = None , bases = (models .Model ,),
47
- user_related_name = '+' ):
47
+ user_related_name = '+' , table_name = None ):
48
48
self .user_set_verbose_name = verbose_name
49
49
self .user_related_name = user_related_name
50
+ self .table_name = table_name
50
51
try :
51
52
if isinstance (bases , six .string_types ):
52
53
raise TypeError
@@ -117,9 +118,8 @@ def create_history_model(self, model):
117
118
attrs .update (self .get_extra_fields (model , fields ))
118
119
# type in python2 wants str as a first argument
119
120
attrs .update (Meta = type (str ('Meta' ), (), self .get_meta_options (model )))
120
- history_options = self .get_history_options (model )
121
- if 'db_history_table' in history_options :
122
- attrs ['Meta' ].db_table = history_options ['db_history_table' ]
121
+ if self .table_name is not None :
122
+ attrs ['Meta' ].db_table = self .table_name
123
123
name = 'Historical%s' % model ._meta .object_name
124
124
registered_models [model ._meta .db_table ] = model
125
125
return python_2_unicode_compatible (
@@ -228,27 +228,6 @@ def get_meta_options(self, model):
228
228
meta_fields ['verbose_name' ] = name
229
229
return meta_fields
230
230
231
- def get_history_options (self , model ):
232
- """
233
- Returns a dictionary of options set to the History inner
234
- class of the historical record model.
235
- """
236
- VALID_OPTIONS = ['db_history_table' ]
237
- if hasattr (model , 'History' ):
238
- history_options = model .History .__dict__ .copy ()
239
- for key in model .History .__dict__ :
240
- # Ignore any private attributes that we doesn't care about, like
241
- # "__module__" or "__dict__".
242
- # NOTE: We can't modify a dictionary's contents while looping
243
- # over it, so we loop over the *original* dictionary instead.
244
- if key .startswith ('_' ):
245
- del history_options [key ]
246
- for option in history_options :
247
- if not option in VALID_OPTIONS :
248
- raise TypeError ("'class History' got invalid attribute: %s" % (option ,))
249
- return history_options
250
- return {}
251
-
252
231
def post_save (self , instance , created , ** kwargs ):
253
232
if not created and hasattr (instance , 'skip_history_when_saving' ):
254
233
return
0 commit comments