Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

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.


git-svn-id: http://code.djangoproject.com/svn/django/trunk@9618 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 5e9c5de78a8b0c0e1700f655febfd317f4ca33ee 1 parent c006ef5
Malcolm Tredinnick authored December 09, 2008

Showing 1 changed file with 12 additions and 5 deletions. Show diff stats Hide diff stats

  1. 17  django/db/models/base.py
17  django/db/models/base.py
@@ -10,7 +10,7 @@
10 10
 
11 11
 import django.db.models.manager     # Imported to register signal handler.
12 12
 from django.core.exceptions import ObjectDoesNotExist, MultipleObjectsReturned, FieldError
13  
-from django.db.models.fields import AutoField
  13
+from django.db.models.fields import AutoField, FieldDoesNotExist
14 14
 from django.db.models.fields.related import OneToOneRel, ManyToOneRel, OneToOneField
15 15
 from django.db.models.query import delete_objects, Q, CollectedObjects
16 16
 from django.db.models.options import Options
@@ -298,12 +298,19 @@ def _set_pk_val(self, value):
298 298
 
299 299
     def serializable_value(self, field_name):
300 300
         """
301  
-        Returns the value of the field name for this instance. If the field
302  
-        is a foreign key, returns the id value, instead of the object.
  301
+        Returns the value of the field name for this instance. If the field is
  302
+        a foreign key, returns the id value, instead of the object. If there's
  303
+        no Field object with this name on the model, the model attribute's
  304
+        value is returned directly.
  305
+
303 306
         Used to serialize a field's value (in the serializer, or form output,
304  
-        for example).
  307
+        for example). Normally, you would just access the attribute directly
  308
+        and not use this method.
305 309
         """
306  
-        field = self._meta.get_field_by_name(field_name)[0]
  310
+        try:
  311
+            field = self._meta.get_field_by_name(field_name)[0]
  312
+        except FieldDoesNotExist:
  313
+            return getattr(self, field_name)
307 314
         return getattr(self, field.attname)
308 315
 
309 316
     def save(self, force_insert=False, force_update=False):

0 notes on commit 5e9c5de

Please sign in to comment.
Something went wrong with that request. Please try again.