code: def get_context(self, name, value, attrs):
          
          context = super(DynamicRawIDWidget, self).get_context(
              name, value, attrs
          )
          model = self.rel.model if VERSION[0] == 2 else self.rel.to
          related_url = reverse(
              'admin:{0}_{1}_changelist'.format(
                  model._meta.app_label, model._meta.object_name.lower()
              ),
              current_app=self.admin_site.name,
          )
  
          params = self.url_parameters()
          if params:
              url = u'?' + u'&'.join(
                  [u'{0}={1}'.format(k, v) for k, v in params.items()]
              )
          else:
              url = u''
          if "class" not in attrs:
              attrs[
                  'class'
              ] = (
                  'vForeignKeyRawIdAdminField'
              )  # The JavaScript looks for this hook.
          app_name = model._meta.app_label.strip()
          model_name = model._meta.object_name.lower().strip()
  
          context.update(
              {
                  'name': name,
                  'app_name': app_name,
                  'model_name': model_name,
                  'related_url': related_url,
                  'url': url,
              }
          )
          return context
docs: Django >= 1.11 variant.