Ticket #7918: subclass-foreignkey.patch

File subclass-foreignkey.patch, 1.3 KB (added by sil, 16 years ago)

Updated to handle fail

  • django/db/models/fields/related.py

     
    225225            val = getattr(instance, self.field.attname)
    226226            if val is None:
    227227                # If NULL is an allowed value, return it.
    228                 if self.field.null:
     228                if self.field.null or isinstance(self.field,OneToOneField):
    229229                    return None
    230230                raise self.field.rel.to.DoesNotExist
    231231            other_field = self.field.rel.get_related_field()
  • django/newforms/models.py

     
    436436            raise Exception("%s has no field named '%s'" % (model, fk_name))
    437437    else:
    438438        # 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)]
    440440        if len(fks_to_parent) == 1:
    441441            fk = fks_to_parent[0]
    442442        elif len(fks_to_parent) == 0:
Back to Top