|
4 | 4 | import importlib
|
5 | 5 | import threading
|
6 | 6 |
|
7 |
| -from django.db import models, router |
8 |
| -from django.db.models.fields.proxy import OrderWrt |
9 | 7 | from django.conf import settings
|
10 | 8 | from django.contrib import admin
|
| 9 | +from django.db import models, router |
| 10 | +from django.db.models.fields.proxy import OrderWrt |
11 | 11 | from django.utils import six
|
12 |
| -from django.utils.encoding import python_2_unicode_compatible |
13 |
| -from django.utils.encoding import smart_text |
| 12 | +from django.utils.encoding import python_2_unicode_compatible, smart_text |
14 | 13 | from django.utils.timezone import now
|
15 |
| -from django.utils.translation import string_concat |
| 14 | +from django.utils.translation import string_concat, ugettext as _ |
| 15 | + |
| 16 | +from . import exceptions |
| 17 | +from .manager import HistoryDescriptor |
16 | 18 |
|
17 | 19 | try:
|
18 | 20 | from django.apps import apps
|
|
26 | 28 | add_introspection_rules(
|
27 | 29 | [], ["^simple_history.models.CustomForeignKeyField"])
|
28 | 30 |
|
29 |
| -from . import exceptions |
30 |
| -from .manager import HistoryDescriptor |
31 | 31 |
|
32 | 32 | registered_models = {}
|
33 | 33 |
|
@@ -213,13 +213,15 @@ def get_instance(self):
|
213 | 213 | return {
|
214 | 214 | 'history_id': models.AutoField(primary_key=True),
|
215 | 215 | 'history_date': models.DateTimeField(),
|
| 216 | + 'history_change_reason': models.CharField(max_length=100, |
| 217 | + null=True), |
216 | 218 | 'history_user': models.ForeignKey(
|
217 | 219 | user_model, null=True, related_name=self.user_related_name,
|
218 | 220 | on_delete=models.SET_NULL),
|
219 | 221 | 'history_type': models.CharField(max_length=1, choices=(
|
220 |
| - ('+', 'Created'), |
221 |
| - ('~', 'Changed'), |
222 |
| - ('-', 'Deleted'), |
| 222 | + ('+', _('Created')), |
| 223 | + ('~', _('Changed')), |
| 224 | + ('-', _('Deleted')), |
223 | 225 | )),
|
224 | 226 | 'history_object': HistoricalObjectDescriptor(model, self.fields_included(model)),
|
225 | 227 | 'instance': property(get_instance),
|
@@ -258,12 +260,14 @@ def post_delete(self, instance, **kwargs):
|
258 | 260 | def create_historical_record(self, instance, history_type):
|
259 | 261 | history_date = getattr(instance, '_history_date', now())
|
260 | 262 | history_user = self.get_history_user(instance)
|
| 263 | + history_change_reason = getattr(instance, 'changeReason', None) |
261 | 264 | manager = getattr(instance, self.manager_name)
|
262 | 265 | attrs = {}
|
263 | 266 | for field in self.fields_included(instance):
|
264 | 267 | attrs[field.attname] = getattr(instance, field.attname)
|
265 | 268 | manager.create(history_date=history_date, history_type=history_type,
|
266 |
| - history_user=history_user, **attrs) |
| 269 | + history_user=history_user, |
| 270 | + history_change_reason=history_change_reason, **attrs) |
267 | 271 |
|
268 | 272 | def get_history_user(self, instance):
|
269 | 273 | """Get the modifying user from instance or middleware."""
|
|
0 commit comments