Skip to content

Commit

Permalink
Allow specifying the database table name when creating the history field
Browse files Browse the repository at this point in the history
  • Loading branch information
tfaris committed Feb 28, 2013
1 parent 706fe60 commit 81dfd52
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions simple_history/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@


class HistoricalRecords(object):
def __init__(self,db_table=None):
self.db_table = db_table

def contribute_to_class(self, cls, name):
self.manager_name = name
self.module = cls.__module__
Expand Down Expand Up @@ -142,9 +145,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 {
'ordering': ('-history_date', '-history_id'),
}
options = { 'ordering': ('-history_date', '-history_id') }
if self.db_table is not None:
options['db_table'] = self.db_table
return options

def post_save(self, instance, created, **kwargs):
if not created and hasattr(instance, 'skip_history_when_saving'):
Expand Down

0 comments on commit 81dfd52

Please sign in to comment.