﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
14518	Field.to_python not called on foreign key IDs	David Wolever	nobody	"Given a subclass of Field like this:

{{{
class MyIDField(Field):
    ...
    def to_python(self, value):
        return to_base_36(value)
}}}

Used like this:

{{{
class Foo(m.Model):
    id = MyIDField(primary_key=True)

class Bar(m.Model):
    foo = m.ForeignKey(Foo)
}}}

Then the `MyIDField.to_python` function isn't called when `Bar.foo_id` is accessed:

{{{
>>> b = Bar.objects.all()[0]
>>> b.foo_id
1234
>>> b.foo.id
'ya'
>>>
}}}

This is annoying for a few reasons, but most significantly because it breaks dropdown menus in admin: even if a value is set for a foreign key, the menu selects the default item (usually `------`). This is because the menu items *have* been `to_python`'d, but the default value has *not* been `to_python`'d).

I'm seeing this in Django 1.2.1.

If this is confirmed as a bug, I can submit test cases."	Bug	closed	Database layer (models, ORM)	dev	Normal	worksforme		David Wolever kitsunde@… info@… anubhav9042@…	Accepted	0	0	0	0	0	0
