Ticket #7918: subclass-foreignkey.patch
File subclass-foreignkey.patch, 1.3 KB (added by , 16 years ago) |
---|
-
django/db/models/fields/related.py
225 225 val = getattr(instance, self.field.attname) 226 226 if val is None: 227 227 # If NULL is an allowed value, return it. 228 if self.field.null :228 if self.field.null or isinstance(self.field,OneToOneField): 229 229 return None 230 230 raise self.field.rel.to.DoesNotExist 231 231 other_field = self.field.rel.get_related_field() -
django/newforms/models.py
436 436 raise Exception("%s has no field named '%s'" % (model, fk_name)) 437 437 else: 438 438 # Try to discover what the ForeignKey from model to parent_model is 439 fks_to_parent = [f for f in opts.fields if isinstance(f, ForeignKey) and f.rel.to == parent_model]439 fks_to_parent = [f for f in opts.fields if isinstance(f, ForeignKey) and issubclass(parent_model,f.rel.to)] 440 440 if len(fks_to_parent) == 1: 441 441 fk = fks_to_parent[0] 442 442 elif len(fks_to_parent) == 0: