@@ -44,9 +44,10 @@ class HistoricalRecords(object):
4444 thread = threading .local ()
4545
4646 def __init__ (self , verbose_name = None , bases = (models .Model ,),
47- user_related_name = '+' ):
47+ user_related_name = '+' , table_name = None ):
4848 self .user_set_verbose_name = verbose_name
4949 self .user_related_name = user_related_name
50+ self .table_name = table_name
5051 try :
5152 if isinstance (bases , six .string_types ):
5253 raise TypeError
@@ -117,9 +118,8 @@ def create_history_model(self, model):
117118 attrs .update (self .get_extra_fields (model , fields ))
118119 # type in python2 wants str as a first argument
119120 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
123123 name = 'Historical%s' % model ._meta .object_name
124124 registered_models [model ._meta .db_table ] = model
125125 return python_2_unicode_compatible (
@@ -228,27 +228,6 @@ def get_meta_options(self, model):
228228 meta_fields ['verbose_name' ] = name
229229 return meta_fields
230230
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-
252231 def post_save (self , instance , created , ** kwargs ):
253232 if not created and hasattr (instance , 'skip_history_when_saving' ):
254233 return
0 commit comments