Django

Code

Changeset 1313

Show
Ignore:
Timestamp:
11/20/05 16:18:41 (2 years ago)
Author:
adrian
Message:

Fixed #527 and #768 -- Fixed longstanding bug with OneToOneFields?. All unit tests now pass

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • django/trunk/django/core/meta/__init__.py

    r1274 r1313  
    755755                        val = f.get_default() 
    756756                else: 
     757                    # Object instance was passed in. 
    757758                    # Special case: You can pass in "None" for related objects if it's allowed. 
    758759                    if rel_obj is None and f.null: 
     
    760761                    else: 
    761762                        try: 
    762                             val = getattr(rel_obj, f.rel.field_name) 
     763                            val = getattr(rel_obj, f.rel.get_related_field().attname) 
    763764                        except AttributeError: 
    764765                            raise TypeError, "Invalid value: %r should be a %s instance, not a %s" % (f.name, f.rel.to, type(rel_obj)) 
     
    893894        if val is None: 
    894895            raise getattr(mod, '%sDoesNotExist' % field_with_rel.rel.to.object_name) 
    895         retrieved_obj = mod.get_object(**{'%s__exact' % field_with_rel.rel.field_name: val}) 
     896        other_field = field_with_rel.rel.get_related_field() 
     897        if other_field.rel: 
     898            params = {'%s__%s__exact' % (field_with_rel.rel.field_name, other_field.rel.field_name): val} 
     899        else: 
     900            params = {'%s__exact'% field_with_rel.rel.field_name: val} 
     901        retrieved_obj = mod.get_object(**params) 
    896902        setattr(self, cache_var, retrieved_obj) 
    897903    return getattr(self, cache_var)