I have added a custom button to my Django Admin by overriding change_form.html
. I'd like this button to read a site_url
field from the model itself, scape that site, and then programatically change the model's form fields (without saving it).. so it can be reviewed and corrected before saving.
I have successfully got my button to print the object by overriding response_change
. I can also pre-populate the template by using extra_context by overriding change_view.
def response_change(self, request, obj):
if '_scrape-site' in request.POST:
print(obj)
return HttpResponseRedirect(".")
return super().response_change(request, obj)
I'd like to be able to enter a site_url
and scrape it using requests/bs4 or scrapy
, and then return those values into the change_form
in the Title and Summary text boxes (see https://i.stack.imgur.com/bbskD.png). Is that possible?