@@ -134,14 +134,20 @@ def create_history_model(self, model):
134
134
return python_2_unicode_compatible (
135
135
type (str (name ), self .bases , attrs ))
136
136
137
+ def fields_included (self , model ):
138
+ fields = []
139
+ for field in model ._meta .fields :
140
+ if field .name not in self .excluded_fields :
141
+ fields .append (field )
142
+ return fields
143
+
137
144
def copy_fields (self , model ):
138
145
"""
139
146
Creates copies of the model's original fields, returning
140
147
a dictionary mapping field name to copied field object.
141
148
"""
142
149
fields = {}
143
- fields_to_copy = set (model ._meta .fields ) - set (self .excluded_fields )
144
- for field in fields_to_copy :
150
+ for field in self .fields_included (model ):
145
151
field = copy .copy (field )
146
152
try :
147
153
field .remote_field = copy .copy (field .remote_field )
@@ -250,7 +256,7 @@ def create_historical_record(self, instance, history_type):
250
256
history_user = self .get_history_user (instance )
251
257
manager = getattr (instance , self .manager_name )
252
258
attrs = {}
253
- for field in instance . _meta . fields :
259
+ for field in self . fields_included ( instance ) :
254
260
attrs [field .attname ] = getattr (instance , field .attname )
255
261
manager .create (history_date = history_date , history_type = history_type ,
256
262
history_user = history_user , ** attrs )
0 commit comments