@@ -179,13 +179,25 @@ class CustomForeignKey(parent_type):
179
179
180
180
def get_attname (self ):
181
181
return self .name
182
-
183
- def do_related_class (self , other , cls ):
182
+
183
+ def get_field (self , other , cls ):
184
184
# this hooks into contribute_to_class() and this is
185
185
# called specifically after the class_prepared signal
186
186
to_field = copy .copy (self .rel .to ._meta .pk )
187
187
field = self
188
- if isinstance (to_field , models .AutoField ):
188
+ if isinstance (to_field , models .OneToOneField ):
189
+ #HACK This creates a new custom foreign key based on to_field,
190
+ # and calls itself with that, effectively making the calls
191
+ # recursive
192
+ temp_field = self .__class__ (to_field .rel .to ._meta .object_name )
193
+ for key , val in to_field .__dict__ .items ():
194
+ if (isinstance (key , basestring )
195
+ and not key .startswith ('_' )):
196
+ setattr (temp_field , key , val )
197
+ field = self .__class__ .get_field (
198
+ temp_field , other , to_field .rel .to )
199
+
200
+ elif isinstance (to_field , models .AutoField ):
189
201
field .__class__ = models .IntegerField
190
202
else :
191
203
field .__class__ = to_field .__class__
@@ -216,6 +228,11 @@ def do_related_class(self, other, cls):
216
228
and not key .startswith (excluded_prefixes )
217
229
and not key in excluded_attributes ):
218
230
setattr (field , key , val )
231
+ return field
232
+
233
+ def do_related_class (self , other , cls ):
234
+ field = self .get_field (other , cls )
235
+
219
236
transform_field (field )
220
237
field .rel = None
221
238
0 commit comments