diff options
| author | Adrian Holovaty <adrian@holovaty.com> | 2005-11-20 22:18:41 +0000 |
|---|---|---|
| committer | Adrian Holovaty <adrian@holovaty.com> | 2005-11-20 22:18:41 +0000 |
| commit | 6f249c856b0723b5b7f30b36f50889e19d12c825 (patch) | |
| tree | fc32fed42d889b7d32450f59bad31a8b9e69cea7 | |
| parent | 887ed3ad2c2d021209d41244fc4234cb168f4ba0 (diff) | |
Fixed #527 and #768 -- Fixed longstanding bug with OneToOneFields. All unit tests now pass
git-svn-id: http://code.djangoproject.com/svn/django/trunk@1313 bcc190cf-cafb-0310-a4f2-bffc1f526a37
| -rw-r--r-- | django/core/meta/__init__.py | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/django/core/meta/__init__.py b/django/core/meta/__init__.py index a8cd4112a1..b61057662c 100644 --- a/django/core/meta/__init__.py +++ b/django/core/meta/__init__.py @@ -754,12 +754,13 @@ def method_init(opts, self, *args, **kwargs): except KeyError: val = f.get_default() else: + # Object instance was passed in. # Special case: You can pass in "None" for related objects if it's allowed. if rel_obj is None and f.null: val = None else: try: - val = getattr(rel_obj, f.rel.field_name) + val = getattr(rel_obj, f.rel.get_related_field().attname) except AttributeError: raise TypeError, "Invalid value: %r should be a %s instance, not a %s" % (f.name, f.rel.to, type(rel_obj)) setattr(self, f.attname, val) @@ -892,7 +893,12 @@ def method_get_many_to_one(field_with_rel, self): mod = field_with_rel.rel.to.get_model_module() if val is None: raise getattr(mod, '%sDoesNotExist' % field_with_rel.rel.to.object_name) - retrieved_obj = mod.get_object(**{'%s__exact' % field_with_rel.rel.field_name: val}) + other_field = field_with_rel.rel.get_related_field() + if other_field.rel: + params = {'%s__%s__exact' % (field_with_rel.rel.field_name, other_field.rel.field_name): val} + else: + params = {'%s__exact'% field_with_rel.rel.field_name: val} + retrieved_obj = mod.get_object(**params) setattr(self, cache_var, retrieved_obj) return getattr(self, cache_var) |
