Commits

Anonymous committed a37594b

Allow the programmer to specify the field used for 'history_id' because AutoField is not always the best choice.

Comments (0)

Files changed (1)

simple_history/models.py

 from manager import HistoryDescriptor
 
 class HistoricalRecords(object):
+    def __init__(self,pk_field=None):
+        if pk_field is None:
+            self.pk_field = models.AutoField(primary_key=True)
+        elif isinstance(pk_field, models.Field) \
+        and pk_field.primary_key:
+            self.pk_field = pk_field
+        else:   
+            raise ValueError("If supplied, 'pk_field' must subclass 'django.db.models.fields.Field' with a primary_key attribute of True.")
+        super(HistoricalRecords,self).__init__()
+    
     def contribute_to_class(self, cls, name):
         self.manager_name = name
         models.signals.class_prepared.connect(self.finalize, sender=cls)
         """
         rel_nm = '_%s_history' % model._meta.object_name.lower()
         return {
-            'history_id': models.AutoField(primary_key=True),
+            'history_id': self.pk_field,
             'history_date': models.DateTimeField(default=datetime.datetime.now),
             'history_type': models.CharField(max_length=1, choices=(
                 ('+', 'Created'),
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.