File tree Expand file tree Collapse file tree 3 files changed +12
-1
lines changed Expand file tree Collapse file tree 3 files changed +12
-1
lines changed Original file line number Diff line number Diff line change @@ -41,6 +41,7 @@ Authors
41
41
- Michael England
42
42
- Gregory Bataille
43
43
- Jesse Shapiro
44
+ - Kevin Foster
44
45
45
46
Background
46
47
==========
Original file line number Diff line number Diff line change @@ -5,6 +5,7 @@ Unreleased
5
5
----------
6
6
- Use get_queryset rather than model.objects in history_view. (gh-303)
7
7
- Change ugettext calls in models.py to ugettext_lazy
8
+ - Resolve issue where model references itself (gh-278)
8
9
9
10
1.9.0 (2017-06-11)
10
11
------------------
Original file line number Diff line number Diff line change @@ -172,8 +172,17 @@ def copy_fields(self, model):
172
172
field_arguments ['to_field' ] = old_field .to_fields [0 ]
173
173
if getattr (old_field , 'db_column' , None ):
174
174
field_arguments ['db_column' ] = old_field .db_column
175
+
176
+ # If old_field.rel.to is 'self' then we have a case where object has a foreign key
177
+ # to itself. In this case we update need to set the `to` value of the field
178
+ # to be set to a model. We can use the old_field.model value.
179
+ if isinstance (old_field .rel .to , str ) and old_field .rel .to == 'self' :
180
+ object_to = old_field .model
181
+ else :
182
+ object_to = old_field .rel .to
183
+
175
184
field = FieldType (
176
- old_field . rel . to ,
185
+ object_to ,
177
186
related_name = '+' ,
178
187
null = True ,
179
188
blank = True ,
You can’t perform that action at this time.
0 commit comments