Author: mtredinnick
Date: 2008-12-09 00:51:23 -0600 (Tue, 09 Dec 2008)
New Revision: 9619

Modified:
   django/branches/releases/1.0.X/django/db/models/base.py
Log:
[1.0.X] Fixed #9775 -- Fixed an oversight from r9601 and allow direct attribute
lookup in the serializable_value() method. This means that abstract
parents that are multi-table children of other models(no, really!!) now
work again.

Backport of r9618 from trunk.


Modified: django/branches/releases/1.0.X/django/db/models/base.py
===================================================================
--- django/branches/releases/1.0.X/django/db/models/base.py     2008-12-09 
06:49:40 UTC (rev 9618)
+++ django/branches/releases/1.0.X/django/db/models/base.py     2008-12-09 
06:51:23 UTC (rev 9619)
@@ -10,7 +10,7 @@
 
 import django.db.models.manager     # Imported to register signal handler.
 from django.core.exceptions import ObjectDoesNotExist, 
MultipleObjectsReturned, FieldError
-from django.db.models.fields import AutoField
+from django.db.models.fields import AutoField, FieldDoesNotExist
 from django.db.models.fields.related import OneToOneRel, ManyToOneRel, 
OneToOneField
 from django.db.models.query import delete_objects, Q, CollectedObjects
 from django.db.models.options import Options
@@ -298,12 +298,19 @@
 
     def serializable_value(self, field_name):
         """
-        Returns the value of the field name for this instance. If the field
-        is a foreign key, returns the id value, instead of the object.
+        Returns the value of the field name for this instance. If the field is
+        a foreign key, returns the id value, instead of the object. If there's
+        no Field object with this name on the model, the model attribute's
+        value is returned directly.
+
         Used to serialize a field's value (in the serializer, or form output,
-        for example).
+        for example). Normally, you would just access the attribute directly
+        and not use this method.
         """
-        field = self._meta.get_field_by_name(field_name)[0]
+        try:
+            field = self._meta.get_field_by_name(field_name)[0]
+        except FieldDoesNotExist:
+            return getattr(self, field_name)
         return getattr(self, field.attname)
 
     def save(self, force_insert=False, force_update=False):


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to