jonashaag / django-addanother

"Add another" buttons outside the Django admin
http://django-addanother.readthedocs.org/
ISC License
50 stars 18 forks source link

Using addanother not for add but for choose ? #53

Open paulz1 opened 2 years ago

paulz1 commented 2 years ago

At first thank you for very good and useful add-ons.

I have mostly a question than an issue. Sorry to ask it here, the issues are probably not for this purpose, but I didn't find any other place to ask it. My problem is that I want to use django-addanother add-on not for add the new item, but to choose from existing one.

In two words...

I have a model with ForeignKey field. In the form this field is done using Select Dropdown menu. I'd like instead to have a button that will open a popup window where user choose the Object, click Submit, then popup is closed and the chosen Object is inserted into initial Form.

So my questions are :

  1. Do you think I could realize such functionality with django-addanother ?

  2. Is this functionality already included in django-addanother ? I could not find any explicit example in the doc.

  3. I allow myself to ask this question as the desired functionality is not very hard to obtain. In fact, if in the very basic example we inherit class PersonCreate not form CreateView but from ListView we could easily get the list of related objects :

    class PersonCreate(CreatePopupMixin, ListView):

    The only question is that I should return from this PersonCreate popup to get it into thi initial form.

Once again, sorry for this not very relevant question.

jonashaag commented 2 years ago

I think we might be able to enable this use case with minimal changes.

You'll have to dig into the Django JS code, start here

https://github.com/jonashaag/django-addanother/blob/f272e268357b5c11b674fe7ace111e14a495dda7/django_addanother/views.py#L47

which leads to

https://github.com/django/django/blob/main/django/contrib/admin/templates/admin/popup_response.html

Maybe it needs changes in the Django code, not sure.

If you find anything helpful, feel free to discuss here.

paulz1 commented 2 years ago

Thank you very much for quick reply :-)

I'm viewing actually respond_script and thinking how I could adapt it to my needs. If this could be realized inside django-addanother (may be creating some class ChoosePopupMixin) it would be probably very useful for me and other peoples.

If I advance or find something on this subject I'll of course share it here.