From 260f9c51127702afcb1d2c669e0ec1855bdea58c Mon Sep 17 00:00:00 2001 From: Malcolm Tredinnick Date: Thu, 29 Nov 2007 19:30:49 +0000 Subject: [PATCH] Fixed #5989 -- Fixed a problem with values being incorrectly reused by reference in field subclassing. Thanks, flupke. git-svn-id: http://code.djangoproject.com/svn/django/trunk@6748 bcc190cf-cafb-0310-a4f2-bffc1f526a37 --- django/db/models/fields/subclassing.py | 4 ++-- tests/modeltests/field_subclassing/models.py | 10 ++++++++++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/django/db/models/fields/subclassing.py b/django/db/models/fields/subclassing.py index 1e4c8ca2e0..36f7e4d934 100644 --- a/django/db/models/fields/subclassing.py +++ b/django/db/models/fields/subclassing.py @@ -28,10 +28,10 @@ class Creator(object): def __get__(self, obj, type=None): if obj is None: raise AttributeError('Can only be accessed via an instance.') - return self.value + return obj.__dict__[self.field.name] def __set__(self, obj, value): - self.value = self.field.to_python(value) + obj.__dict__[self.field.name] = self.field.to_python(value) def make_contrib(func=None): """ diff --git a/tests/modeltests/field_subclassing/models.py b/tests/modeltests/field_subclassing/models.py index 6182266c22..97804f5cd5 100644 --- a/tests/modeltests/field_subclassing/models.py +++ b/tests/modeltests/field_subclassing/models.py @@ -103,4 +103,14 @@ TypeError: Invalid lookup type: 'lt' >>> obj = list(serializers.deserialize("json", stream))[0] >>> obj.object == m True + +# Test retrieving custom field data +>>> m.delete() +>>> m1 = MyModel(name="1", data=Small(1, 2)) +>>> m1.save() +>>> m2 = MyModel(name="2", data=Small(2, 3)) +>>> m2.save() +>>> for m in MyModel.objects.all(): print unicode(m.data) +12 +23 """}