Commits

João Pedro Francese committed 0b8291c Draft

Fix the history admin to work when the manager attribute in the model is not named 'history'.

  • Participants
  • Parent commits 0cf6bd0
  • Tags release-1.1.3

Comments (0)

Files changed (3)

             data_files.append(os.path.join(prefix, f))
 
 setup(name='simple_history',
-      version='1.1.2',
+      version='1.1.3',
       description='Store Django model history with the ability to revert back to a specific change at any time.',
       author='Corey Bertram',
       author_email='corey@qr7.com',

File simple_history/admin.py

         opts = model._meta
         app_label = opts.app_label
         pk_name = opts.pk.attname
-        action_list = model.history.filter(**{pk_name: object_id})
+        history = getattr(model, model._meta.simple_history_manager_attribute)
+        action_list = history.filter(**{pk_name: object_id})
         # If no history was found, see whether this object even exists.
         obj = get_object_or_404(model, pk=unquote(object_id))
         context = {
     def history_form_view(self, request, object_id, version_id):
         original_model = self.model
         original_opts = original_model._meta
-        model = self.model.history.model
+        history = getattr(self.model, self.model._meta.simple_history_manager_attribute)
+        model = history.model
         opts = model._meta
         app_label = opts.app_label
         pk_name = original_opts.pk.attname

File simple_history/models.py

 
         descriptor = HistoryDescriptor(history_model)
         setattr(sender, self.manager_name, descriptor)
+        sender._meta.simple_history_manager_attribute = self.manager_name
 
     def create_history_model(self, model):
         """