Question: Unfortunately i can provide only the output of the request and not the full code since it contains quite private infos, basically when printing the request as text file i get a json one, something like that:

```
{"paymentResource":{"paymentToken":"PAYID-MEJ------","intent":"authorize","redirectUrl":"https://www.paypal.com/checkoutnow?nolegacy=1\u0026token=EC-5JS-----2S","authenticateUrl":null}}

```

How can i scrape that Paypal url? tried by doing this but it didn't worked (ppstep2 is the name of the request):

```
content = ppstep2.json()
pp = content["redirectUrl"]

```

I only get this error while doing it:

```
pp = content["redirectUrl"]
KeyError: 'redirectUrl'

```

Answer: 
As [shahbaz ahmad](https://stackoverflow.com/users/7584066/shahbaz-ahmad) suggested, you can use `ModelAdmin`'s [`autocomplete_fields`](https://docs.djangoproject.com/en/3.2/ref/contrib/admin/#django.contrib.admin.ModelAdmin.autocomplete_fields) which creates an `select` with autocompletion.

But if you're stuck with Django's foreign key widget, because, for instance, you have records which look the same and are indistinguishable in autocomplete, there is a solution.

It turns out `ModelAdmin` has a [`get_form`](https://docs.djangoproject.com/en/3.2/ref/contrib/admin/#django.contrib.admin.ModelAdmin.get_form) method that you can use to retrieve the `ModelForm` used on the admin page. This method accepts a `fields` kwargs that you can use to select the fields you want to retrieve in the form. Use it like this:

```py
class MyAdmin(ModelAdmin):
    # define the admin subpath to your intermediate page
    def get_urls(self):
        return [
            path(
                "intermediate_page/",
                self.admin_site.admin_view(self.intermediate_page),
                name="intermediate_page",
            ),
            *super().get_urls(),
        ]

    def intermediate_page(self, request):
        context = {
            # The rest of the context from admin
            **self.admin_site.each_context(request),
            # Retrieve the admin form
            "form": self.get_form(
                request,
                fields=[], # the fields you're interested in
            )
        }

        return render(request, "admin/intermediate_page.html", context)

```

If your field is read only – which was my case – there's a workaround to an editable field: you can override the [`get_readonly_fields`](https://docs.djangoproject.com/en/3.2/ref/contrib/admin/#django.contrib.admin.ModelAdmin.get_readonly_fields) method which is called by `get_form`.

This method accepts an `obj` parameter which usually takes the model of the object being edited or `None` when creating a new entry. You can hijack this parameter to force `get_readonly_fields` exclude fields from read only fields:

```py
def get_readonly_fields(self, request, obj=None):
    readony_fields = super().get_readonly_fields(request, obj)
    if not (
        isinstance(obj, dict)
        and isinstance(obj.get("exclude_from_readonly_fields"), Collection)
    ):
        return readony_fields

    return set(readony_fields) - set(obj["exclude_from_readonly_fields"])

```

`get_form` also has this `obj` parameter which it passes down to `get_readonly_fields` so you can call it like this:

```py
# the fields you're interested in
include_fields = []

self.get_form(
    request,
    obj={"exclude_from_readonly_fields": include_fields},
    fields=include_fields
)

```
Override changelist template of YourModelAdmin class to add one more button apart from add button.

```
@admin.register(YourModel)
class YourModelAdmin(admin.ModelAdmin):
    change_list_template = "custom_your_model_change_list.html"

```

In custom\_your\_model\_change\_list.html,

```
{% extends "admin/change_list.html" %}

{% block  object-tools-items %}
    <li>
      <a class="button" href="{% url 'your_reassign_url_name' %}">Reassign</a>
    </li>
{{ block.super }}
{% endblock %}

```

Mapped a view to 'your\_reassign\_url\_name' to processed your request.

In urls.py,

```
urlpatterns = [
    path('reassign/', YourReassignView, name='your_reassign_url_name'),
]

```

forms.py,

```
class ReassignForm(forms.Form):
    # your reassign field
    reassign_field = forms.ModelChoiceField(queryset='your queryset')
    # Select multiple objects 
    updatable_objects = forms.ModelMultipleChoiceField(queryset='All objects queryset',
                                                    widget=forms.CheckboxSelectMultiple)

```

In views.py, On GET request you render a form with your required fields and on submit your update your data (reassign values) and after that you redirect admin change\_list page.

```
def YourReassignView(request):
    if request.method == 'POST':
        form = ReassignForm(request.POST)
        if form.is_valid():
            # you get value after form submission
            reassign_field = form.cleaned_data.get('reassign_field')
            updatable_objects = form.cleaned_data.get('updatable_objects')

            # your update query
            YourModel.objects.filter(
                    id__in=updatable_objects.values('id')
                ).update(field_name=reassign_field)

            #after that you redirect admin change_list page with a success message
            messages.success(request, 'Successfully reassign')
            return redirect(reverse('admin:app_label_model_name_changelist'))
        else:
            context_data = {'form': form}
            return render(request, 'reassign_template.html', context=context_data)
    else:
        form = ReassignForm()
        context_data = {'form': form}
        return render(request, 'reassign_template.html', context=context_data)

```

In reassign\_template.html,

```
<form method="POST" action="{% url 'your_reassign_url_name' %}">
    {% csrf_token %}
    {{ form.as_p }}
    <br>
    <input type="submit" value="submit">
</form>

```