﻿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
26524	Django Admin list_display - Unable to display foreign key id	Cristiano Coelho	nobody	"Given these two models.


{{{
class A(models.Model):
	name = models.CharField(max_length=100)

	def __unicode__(self):
		return self.name

class B(models.Model):
	name = models.CharField(max_length=100)
	fk = models.ForeignKey(A)
	
	def __unicode__(self):
		return self.name
}}}

And these model admin


{{{
class AAdmin(admin.ModelAdmin):
    list_display = ('id','name')
admin.site.register(A, AAdmin)

class BAdmin(admin.ModelAdmin):
    list_display = ('id','name','fk_id','fk')
admin.site.register(B, BAdmin)
}}}

As you see, for BAdmin I'm trying to display the actual id of the foreign key, so I prevent an additional unwanted join (or worse, one query per related object if no select related is added). However, the admin page refuses to display the id and instead renders the whole object (calling the __unicode__ method) which causes the additional join I don't want.
In order to demostrate it I also added the 'fk' relation which works as expected

The change list result is then


{{{
1	test B	test A	test A
}}}

where it should be

{{{
1	test B	1	test A
}}}


In order to work around it, I can define a callable that just returns the id property, but that's terrible because I lose any sort option on it plus I need to write quite a few more lines."	Bug	new	contrib.admin	1.9	Normal		admin list_display changelist	Cristiano Coelho	Unreviewed	0	0	0	0	0	0
