Django

Code

Changeset 8957

Show
Ignore:
Timestamp:
09/03/08 17:45:33 (10 months ago)
Author:
mtredinnick
Message:

Fixed #8841 -- Fixed a case of ForeignKeys? to models constructed with
inheritance.

This patch is uglier than it needs to be (see comment in patch) to ensure no
accidental bug is introduced just before 1.0. We'll clean it up later.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • django/trunk/django/forms/models.py

    r8872 r8957  
    571571    def choice(self, obj): 
    572572        if self.field.to_field_name: 
    573             key = getattr(obj, self.field.to_field_name) 
     573            # FIXME: The try..except shouldn't be necessary here. But this is 
     574            # going in just before 1.0, so I want to be careful. Will check it 
     575            # out later. 
     576            try: 
     577                key = getattr(obj, self.field.to_field_name).pk 
     578            except AttributeError: 
     579                key = getattr(obj, self.field.to_field_name) 
    574580        else: 
    575581            key = obj.pk