Commits

Trey Hunner  committed 32f0ede Draft

Rename ``changed_by`` column to ``history_user``

  • Participants
  • Parent commits 972c9a6

Comments (0)

Files changed (3)

File simple_history/admin.py

         """
         Add the admin user to a special model attribute for reference after save
         """
-        obj._changed_by_user = request.user
+        obj._history_user = request.user
         super(SimpleHistoryAdmin, self).save_model(request, obj, form, change)

File simple_history/models.py

         return {
             'history_id': models.AutoField(primary_key=True),
             'history_date': models.DateTimeField(auto_now_add=True),
+            'history_user': models.ForeignKey(User, null=True),
             'history_type': models.CharField(max_length=1, choices=(
                 ('+', 'Created'),
                 ('~', 'Changed'),
                 ('-', 'Deleted'),
             )),
             'history_object': HistoricalObjectDescriptor(model),
-            'changed_by': models.ForeignKey(User, null=True),
             'instance': property(get_instance),
             'revert_url': revert_url,
             '__unicode__': lambda self: u'%s as of %s' % (self.history_object,
         self.create_historical_record(instance, '-')
 
     def create_historical_record(self, instance, type):
-        changed_by = getattr(instance, '_changed_by_user', None)
+        history_user = getattr(instance, '_history_user', None)
         manager = getattr(instance, self.manager_name)
         attrs = {}
         for field in instance._meta.fields:
             attrs[field.attname] = getattr(instance, field.attname)
-        manager.create(history_type=type, changed_by=changed_by, **attrs)
+        manager.create(history_type=type, history_user=history_user, **attrs)
 
 
 class HistoricalObjectDescriptor(object):

File simple_history/templates/simple_history/object_history.html

 							<tr>
 								<th scope="row"><a href="{{ action.revert_url }}">{{ action.history_date }}</a></th>
 								<td>{{ action.get_history_type_display }}</td>
-								<td>{{ action.changed_by }}</td>
+								<td><a href="{% url admin:auth_user_change action.history_user_id %}">{{ action.history_user }}</a></td>
 							</tr>
 						{% endfor %}
 					</tbody>