diff options
author | Justin Bronn <jbronn@gmail.com> | 2008-08-05 17:15:33 +0000 |
---|---|---|
committer | Justin Bronn <jbronn@gmail.com> | 2008-08-05 17:15:33 +0000 |
commit | aa239e3e5405933af6a29dac3cf587b59a099927 (patch) | |
tree | ea2cbd139c9a8cf84c09e0b2008bff70e05927ef /tests/regressiontests/one_to_one_regress/models.py | |
parent | 45b73c9a4685809236f84046cc7ffd32a50db958 (diff) | |
download | django-attic/gis.tar.gz |
gis: Merged revisions 7981-8001,8003-8011,8013-8033,8035-8036,8038-8039,8041-8063,8065-8076,8078-8139,8141-8154,8156-8214 via svnmerge from trunk.archive/attic/gisattic/gis
git-svn-id: http://code.djangoproject.com/svn/django/branches/gis@8215 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'tests/regressiontests/one_to_one_regress/models.py')
-rw-r--r-- | tests/regressiontests/one_to_one_regress/models.py | 35 |
1 files changed, 33 insertions, 2 deletions
diff --git a/tests/regressiontests/one_to_one_regress/models.py b/tests/regressiontests/one_to_one_regress/models.py index 99022882f2..66d00d7223 100644 --- a/tests/regressiontests/one_to_one_regress/models.py +++ b/tests/regressiontests/one_to_one_regress/models.py @@ -22,6 +22,10 @@ class Bar(models.Model): def __unicode__(self): return u"%s the bar" % self.place.name +class UndergroundBar(models.Model): + place = models.OneToOneField(Place, null=True) + serves_cocktails = models.BooleanField() + class Favorites(models.Model): name = models.CharField(max_length = 50) restaurants = models.ManyToManyField(Restaurant) @@ -42,7 +46,7 @@ __test__ = {'API_TESTS':""" >>> f.restaurants.all() [<Restaurant: Demon Dogs the restaurant>] -# Regression test for #7173: Check that the name of the cache for the +# Regression test for #7173: Check that the name of the cache for the # reverse object is correct. >>> b = Bar(place=p1, serves_cocktails=False) >>> b.save() @@ -53,7 +57,7 @@ __test__ = {'API_TESTS':""" # # Regression test for #6886 (the related-object cache) -# +# # Look up the objects again so that we get "fresh" objects >>> p = Place.objects.get(name="Demon Dogs") @@ -76,6 +80,12 @@ False >>> p.restaurant is r2 True +# Assigning None succeeds if field is null=True. +>>> ug_bar = UndergroundBar.objects.create(place=p, serves_cocktails=False) +>>> ug_bar.place = None +>>> ug_bar.place is None +True + # Assigning None fails: Place.restaurant is null=False >>> p.restaurant = None Traceback (most recent call last): @@ -88,4 +98,25 @@ Traceback (most recent call last): ... ValueError: Cannot assign "<Place: Demon Dogs the place>": "Place.restaurant" must be a "Restaurant" instance. +# Creation using keyword argument should cache the related object. +>>> p = Place.objects.get(name="Demon Dogs") +>>> r = Restaurant(place=p) +>>> r.place is p +True + +# Creation using keyword argument and unsaved related instance (#8070). +>>> p = Place() +>>> r = Restaurant(place=p) +>>> r.place is p +True + +# Creation using attname keyword argument and an id will cause the related +# object to be fetched. +>>> p = Place.objects.get(name="Demon Dogs") +>>> r = Restaurant(place_id=p.id) +>>> r.place is p +False +>>> r.place == p +True + """} |