# How to open a popup?

**URL:** <https://forum.djangoproject.com/t/how-to-open-a-popup/20856>\
**Category:** Templates & Frontend\
**Created:** [May 10, 2023, 4:39pm UTC](https://forum.djangoproject.com/t/how-to-open-a-popup/20856 "2023-05-10T16:39:42Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![RichardWoj](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/richardwoj/32/12824_2.png) [@RichardWoj](https://forum.djangoproject.com/u/RichardWoj)\
**Post date:** [May 10, 2023, 4:39pm UTC](https://forum.djangoproject.com/t/how-to-open-a-popup/20856/1 "2023-05-10T16:39:42Z")

</div>

Hi,  
In the admin site when creating/updating an object A which has field “fk” which is a foreign key related to an object B (displayed in a select element) you can create/update objects B in a popup window.

I am wondering how to open this new window with Django. I did not find anything about this…

Thanks four your help

Richard

---

<div class="post-metadata">

**Author:** ![KenWhitesell](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/kenwhitesell/32/280_2.png) [@KenWhitesell](https://forum.djangoproject.com/u/KenWhitesell)\
**Post date:** [May 10, 2023, 5:04pm UTC](https://forum.djangoproject.com/t/how-to-open-a-popup/20856/2 "2023-05-10T17:04:06Z")

</div>

It can’t be done directly by Django. It has to be done using some JavaScript in the browser. (It can be done either directly in JavaScript, or using a library such as jQuery or HTMX.)

In the admin, the green plus sign triggers JavaScript to open a new window for the form.

You can find the code for what the admin is doing in `django.contrib.admin.static.admin.js.admin.RelatedObjectLookups.js`

---

<div class="post-metadata">

**Author:** ![RichardWoj](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/richardwoj/32/12824_2.png) [@RichardWoj](https://forum.djangoproject.com/u/RichardWoj)\
**Post date:** [May 11, 2023, 5:38pm UTC](https://forum.djangoproject.com/t/how-to-open-a-popup/20856/3 "2023-05-11T17:38:35Z")

</div>

Thanks Ken,

I understand the javascript is very generic, allowing to open several popus in case a related object has its own related object.

I am now able to open the popup, but I have troubles regarding how to define the url to redirect to at the end of my creation view (generic CreateView) and to get the select choice up to date…

```auto
class Create_framework_agreement(CreateView):
    model = Framework_agreement
    fields=['number', 'company', 'signature_date']

```

I guess that the view has to handle “\_to\_field=id” and \_“popup=1” variables…

Could you give me some hints?

Thanks

---

<div class="post-metadata">

**Author:** ![KenWhitesell](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/kenwhitesell/32/280_2.png) [@KenWhitesell](https://forum.djangoproject.com/u/KenWhitesell)\
**Post date:** [May 11, 2023, 5:47pm UTC](https://forum.djangoproject.com/t/how-to-open-a-popup/20856/4 "2023-05-11T17:47:46Z")

</div>

> [@RichardWoj](#):
>
> Could you give me some hints?

Unfortunately I can’t. For the few cases where I have done such things, I’ve used the modal pop-up technique using [jQuery](https://jqueryui.com/dialog/#modal-form) or [Bootstrap](https://getbootstrap.com/docs/4.0/components/modal/)

---

<div class="post-metadata">

**Author:** ![RichardWoj](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/richardwoj/32/12824_2.png) [@RichardWoj](https://forum.djangoproject.com/u/RichardWoj)\
**Post date:** [May 12, 2023, 7:21am UTC](https://forum.djangoproject.com/t/how-to-open-a-popup/20856/5 "2023-05-12T07:21:10Z")

</div>

Thanks Ken,

I will invstigate this track…

Best regards

Richard

---

<div class="post-metadata">

**Author:** ![jpmc](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/jpmc/32/19723_2.png) [@jpmc](https://forum.djangoproject.com/u/jpmc)\
**Post date:** [March 7, 2024, 8:23pm UTC](https://forum.djangoproject.com/t/how-to-open-a-popup/20856/6 "2024-03-07T20:23:36Z")

</div>

I copy the link content from the browser inspector in the django admin and works for me:

```auto
'<a class="related-widget-wrapper-link add-related"'
'id="add_id_manager" data-popup="yes"'
'href="{}">action</a>'

```

This button open a new window like a edit or add new model with plus or pensil buttons.
