I'm trying to find some documentation of how to use the ForeignKeyRawIdWidget in my own forms. Currently I keep getting the error, "init() takes at least 2 non-keyword arguments (1 given)" which tells me nothing.
Any help would be most appreciated. Googling this turns up little but dev conversations and no examples that I can find of how to implement it.
Update: This is solved; see solution below.
As of the Django 1.5, this works to reuse the ForeignKeyRawIdWidget in non-admin forms.
Update
Django 2.0 is deprecating
field.rel
in favor offield.remote_field
. You might want to use this instead (also works on Django 1.11):This is from the source code (
django.contrib.admin.widgets
):From the remaining code, I would guess that
rel
is the foreign key field of your model. At one point, the code checksself.rel.limit_choices_to
, and this attribute (limit_choices_to
) can only be set on aForgeinKey
field.