I am using Python 3.7.10 with Django 3.1.6, and I have used the following code to create an admin popup that will be triggered when clicking on the "edit_link":
class EditLinkWidget(forms.URLInput):
def render(self, name, value, attrs, renderer):
super().render(name, value, attrs, renderer)
if not value:
return ''
return mark_safe(f'<a class="related-widget-wrapper-link change-related" href="{value}?_to_field=id&_popup=1" '\
'data-href-template="{}?_to_field=id&_popup=1">Edit</a>').format(
re.sub("(\d+)", "__fk__", value))
class PageForm(TranslatableModelForm):
edit_link = forms.CharField(widget=EditLinkWidget, required=False, disabled=True)
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
if self.instance.pk:
self.fields['edit_link'].initial = f'/admin/cms/car/{self.instance.car_id}/change/')
class Meta:
model = User
fields = ('edit_link',)
It works great, but the problem is that the popup doesn't close automatically when I click on the Save button, throwing the following javascript error:
Does somebody know how can I fix it so the popup can be closed automatically? I guess it should communicate with the parent admin page somehow?
