| 127 | def value_from_object(self, obj) : |
| 128 | """ |
| 129 | If the foreign key is a subclassed field, we need to convert the value |
| 130 | to its python representation. This function is called by model_to_dict, |
| 131 | which presents the values as a dictionary to the form. |
| 132 | getattr() will put the database value on the dict by default as that is |
| 133 | what the real relationship represents. In the common (unsubclassed) |
| 134 | case, they will be the same value, however if subclassed this results |
| 135 | in: |
| 136 | a) get_prep_value on the custom model field being called with database |
| 137 | value. Working around this and just returning the value results in: |
| 138 | b) Select widget not being able to match the database representation |
| 139 | with the python representation. |
| 140 | """ |
| 141 | return self.rel.get_related_field().to_python(getattr(obj, self.attname)) |
| 142 | |