﻿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
13527	Allow column on ForeignKey	malthe	nobody	"Currently, on the many-side of a `ManyToOne` relation, the underlying value of the relation is always stored in `fieldname_id` (both on the database side and in the ORM). However, this value will often be meaningful on its own and it should be possible to explicitly provide a name, e.g. `from_field` (the database column name would be ""%(from_field)s_id"".)

The following implements this:

{{{
class CustomForeignKey(models.ForeignKey):
    def __init__(self, *args, **kwargs):
        self.from_field = kwargs.pop('from_field')
        if self.from_field:
            kwargs.setdefault('db_column', ""%s_id"" % self.from_field)
        return super(CustomForeignKey, self).__init__(*args, **kwargs)

    def get_attname(self):
        return self.from_field or ""%s_id"" % self.name
}}}"		closed	Database layer (models, ORM)	1.1		wontfix			Unreviewed	0	0	0	0	0	0
