Is there a simple way of overriding/pass a parameter to the popup url automatically created by django-admin built-in autocomplete/select2 widget to create a new foreign key object? This url is embedded in the green cross (see picture).
I didn't come across any well described solutions.
So the default url is pointing towards admin/app/model/add/?_to_field=id&_popup=1 but I would like to add a parameter admin/app/model/add/?_to_field=id&_popup=1&field_1=100 in order to pre-populate some fieds on the popup add_view.
Any leads?
As per Maxim's answer :
def formfield_for_dbfield(self, db_field, request, **kwargs):
if db_field.name == "clinical_exam":
widget = super(ConsultationAdmin, self).formfield_for_dbfield(db_field, request, **kwargs).widget
widget.template_name = 'admin/related_widget_wrapper_with_id.html'
widget.attrs.update({'your_parameter': 'you can use it after in template'})
print(db_field)
return db_field.formfield(widget=widget)
return super(ConsultationAdmin, self).formfield_for_dbfield(db_field, request, **kwargs)
