Skip to content

Commit

Permalink
Fixed #9775 -- Fixed an oversight from r9601 and allow direct attribute
Browse files Browse the repository at this point in the history
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
malcolmt committed Dec 9, 2008
1 parent c006ef5 commit 5e9c5de
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions django/db/models/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -298,12 +298,19 @@ def _set_pk_val(self, value):

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):
Expand Down

0 comments on commit 5e9c5de

Please sign in to comment.