2525 add_introspection_rules (
2626 [], ["^simple_history.models.CustomForeignKeyField" ])
2727
28-
2928registered_models = {}
3029
3130
@@ -69,6 +68,7 @@ def save_without_historical_record(self, *args, **kwargs):
6968 finally :
7069 del self .skip_history_when_saving
7170 return ret
71+
7272 setattr (cls , 'save_without_historical_record' ,
7373 save_without_historical_record )
7474
@@ -156,18 +156,15 @@ def copy_fields(self, model):
156156 fields = {}
157157 for field in self .fields_included (model ):
158158 field = copy .copy (field )
159- try :
160- field .remote_field = copy .copy (field .remote_field )
161- except AttributeError :
162- field .rel = copy .copy (field .rel )
159+ field .remote_field = copy .copy (field .remote_field )
163160 if isinstance (field , OrderWrt ):
164161 # OrderWrt is a proxy field, switch to a plain IntegerField
165162 field .__class__ = models .IntegerField
166163 if isinstance (field , models .ForeignKey ):
167164 old_field = field
168165 field_arguments = {'db_constraint' : False }
169166 if (getattr (old_field , 'one_to_one' , False ) or
170- isinstance (old_field , models .OneToOneField )):
167+ isinstance (old_field , models .OneToOneField )):
171168 FieldType = models .ForeignKey
172169 else :
173170 FieldType = type (old_field )
@@ -176,13 +173,15 @@ def copy_fields(self, model):
176173 if getattr (old_field , 'db_column' , None ):
177174 field_arguments ['db_column' ] = old_field .db_column
178175
179- # If old_field.rel.to is 'self' then we have a case where object has a foreign key
180- # to itself. In this case we update need to set the `to` value of the field
181- # to be set to a model. We can use the old_field.model value.
182- if isinstance (old_field .rel .to , str ) and old_field .rel .to == 'self' :
176+ # If old_field.remote_field.model is 'self' then we have a
177+ # case where object has a foreign key to itself. In this case
178+ # we need to set the `model` value of the field to a model. We
179+ # can use the old_field.model value.
180+ if isinstance (old_field .remote_field .model , str ) and \
181+ old_field .remote_field .model == 'self' :
183182 object_to = old_field .model
184183 else :
185- object_to = old_field .rel . to
184+ object_to = old_field .remote_field . model
186185
187186 field = FieldType (
188187 object_to ,
0 commit comments