|
11 | 11 | from django.db import models
|
12 | 12 | from django.db.models import ManyToManyField
|
13 | 13 | from django.db.models.fields.proxy import OrderWrt
|
14 |
| -from django.forms.models import model_to_dict |
15 | 14 | from django.urls import reverse
|
16 | 15 | from django.utils import timezone
|
17 | 16 | from django.utils.encoding import smart_str
|
@@ -594,20 +593,26 @@ def diff_against(self, old_history, excluded_fields=None):
|
594 | 593 | )
|
595 | 594 | )
|
596 | 595 | if excluded_fields is None:
|
597 |
| - excluded_fields = [] |
| 596 | + excluded_fields = set() |
| 597 | + |
| 598 | + excluded_fields = set(excluded_fields).union(self._history_excluded_fields) |
| 599 | + |
| 600 | + fields = { |
| 601 | + f.name |
| 602 | + for f in old_history.instance_type._meta.fields |
| 603 | + if f.name not in excluded_fields |
| 604 | + } |
| 605 | + |
598 | 606 | changes = []
|
599 | 607 | changed_fields = []
|
600 |
| - old_values = model_to_dict(old_history.instance) |
601 |
| - current_values = model_to_dict(self.instance) |
602 |
| - for field, new_value in current_values.items(): |
603 |
| - if field in excluded_fields: |
604 |
| - continue |
605 |
| - if field in old_values: |
606 |
| - old_value = old_values[field] |
607 |
| - if old_value != new_value: |
608 |
| - change = ModelChange(field, old_value, new_value) |
609 |
| - changes.append(change) |
610 |
| - changed_fields.append(field) |
| 608 | + |
| 609 | + for field in fields: |
| 610 | + old_value = getattr(old_history, field) |
| 611 | + current_value = getattr(self, field) |
| 612 | + |
| 613 | + if old_value != current_value: |
| 614 | + changes.append(ModelChange(field, old_value, current_value)) |
| 615 | + changed_fields.append(field) |
611 | 616 |
|
612 | 617 | return ModelDelta(changes, changed_fields, old_history, self)
|
613 | 618 |
|
|
0 commit comments