to_field in admin

21 views
Skip to first unread message

chr

unread,
Aug 28, 2008, 4:34:55 AM8/28/08
to Django users
hi. i've got a model like this:

class Inventory(models.Model):
barcode = models.PositiveIntegerField(unique=True)
parent = models.ForeignKey('self', to_field='barcode', blank=True,
null=True)
name = models.CharField(blank=False)

and i get:
>>> i = Inventory.objects.get(barcode=115716)
>>> i
<Inventory: Apple Mighty Mouse>
>>> i.parent
<Inventory: Apple iMac>

which is fine. whereas in the admin the select-widget will have the
item selected whose id accidentally matches the barcode. i.e. the
values in the select-widget aren't the values from barcode but the pk.
<option value="247">Apple Mighty Mouse</option>

i couldn't find this behaviour in the admin documented anywhere.

so, is the bug in my model, the lack of documentation or the admin?

many thanks in advance.
cheers. chr

Karen Tracey

unread,
Aug 28, 2008, 12:09:35 PM8/28/08
to django...@googlegroups.com

I believe it's a bug admin.  I've opened a ticket:

http://code.djangoproject.com/ticket/8648

Karen

chr

unread,
Aug 29, 2008, 1:33:28 AM8/29/08
to Django users
thanks for your help. the patch works great.

cheers. chr
Reply all
Reply to author
Forward
0 new messages