What is the correct argument for ForeignKeyRawIdWidget?
I have an admin class that uses raw_id_fields. Instead of displaying a numeric key, I would like to convert it to __unicode__
for the corresponding foreign key object.
I thought I needed to add a form to the admin class for this. This form will be the one in which the field I want to change is overridden by my own widgets.
As an intermediate step, I just want to duplicate the existing behavior - so the raw id field will be displayed with its adjacent icon. I have a form with widgets ForeignKeyRawIdWidget
. This widget needs an argument, although I don't know what to give it. For example I tried ForeignKeyRawIdWidget(DBObjectName.objects.get(pk=53))
but I get an error. DBObjectName has no 'to' attribute.
It can be seen from its definition in related.py that the widget needs an argument, but I don't know what it is looking for.
a source to share
It looks for an argument in the form Class._meta.get_field('field to link').rel
.
For example, I have a class called Photo, whose image field is a ForeignKey to a different class, and I want the ForeignKey widget to look different. The argument required for the foreignKeyRawIDWidget parameter for rel is Photo._meta.get_field('image').rel
.
a source to share