Changeset 8185 for django/trunk/tests/regressiontests/many_to_one_regress
- Timestamp:
- 08/01/08 18:16:59 (4 months ago)
- Files:
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
django/trunk/tests/regressiontests/many_to_one_regress/models.py
r7778 r8185 56 56 57 57 # 58 # Tests of ForeignKey assignment and the related-object cache (see #6886) 58 # Tests of ForeignKey assignment and the related-object cache (see #6886). 59 59 # 60 60 >>> p = Parent.objects.create(name="Parent") 61 61 >>> c = Child.objects.create(name="Child", parent=p) 62 62 63 # Look up the object again so that we get a "fresh" object 63 # Look up the object again so that we get a "fresh" object. 64 64 >>> c = Child.objects.get(name="Child") 65 65 >>> p = c.parent 66 66 67 # Accessing the related object again returns the exactly same object 67 # Accessing the related object again returns the exactly same object. 68 68 >>> c.parent is p 69 69 True 70 70 71 # But if we kill the cache, we get a new object 71 # But if we kill the cache, we get a new object. 72 72 >>> del c._parent_cache 73 73 >>> c.parent is p 74 74 False 75 75 76 # Assigning a new object results in that object getting cached immediately 76 # Assigning a new object results in that object getting cached immediately. 77 77 >>> p2 = Parent.objects.create(name="Parent 2") 78 78 >>> c.parent = p2 … … 80 80 True 81 81 82 # Assigning None fails: Child.parent is null=False 82 # Assigning None succeeds if field is null=True. 83 >>> p.bestchild = None 84 >>> p.bestchild is None 85 True 86 87 # Assigning None fails: Child.parent is null=False. 83 88 >>> c.parent = None 84 89 Traceback (most recent call last): … … 92 97 ValueError: Cannot assign "<First: First object>": "Child.parent" must be a "Parent" instance. 93 98 94 # Test of multiple ForeignKeys to the same model (bug #7125) 99 # Creation using keyword argument should cache the related object. 100 >>> p = Parent.objects.get(name="Parent") 101 >>> c = Child(parent=p) 102 >>> c.parent is p 103 True 95 104 105 # Creation using keyword argument and unsaved related instance (#8070). 106 >>> p = Parent() 107 >>> c = Child(parent=p) 108 >>> c.parent is p 109 True 110 111 # Creation using attname keyword argument and an id will cause the related 112 # object to be fetched. 113 >>> p = Parent.objects.get(name="Parent") 114 >>> c = Child(parent_id=p.id) 115 >>> c.parent is p 116 False 117 >>> c.parent == p 118 True 119 120 121 # 122 # Test of multiple ForeignKeys to the same model (bug #7125). 123 # 96 124 >>> c1 = Category.objects.create(name='First') 97 125 >>> c2 = Category.objects.create(name='Second')
