ModelForm : pass the object's id as extra parameter in AJAX call
See original GitHub issueHi !
I have a Team model and a Member model. The Team model has a captain field.
Now, in my ModelForm, for the captain field, I want to filter the autocomplete to show only members of the team that I’m editing. This means I need to pass a team_id parameter alongside the q parameter.
I think it’s a fairly commun scenario, just like forward=['continent']. I googled the issue and found some links, but they all are quite complex hacks combining advanced django and javascript, and I couldn’t make them work (I’m no javascript expert).
I’d suggest either :
- add an option like
forwardbut to send the modelform’s instance’s pk instead - document the easiest way to get that result
Thanks a lot for the awesome module !
Issue Analytics
- State:
- Created 7 years ago
- Comments:15 (11 by maintainers)
Top Results From Across the Web
django: passing data via ajax to views, and then into forms for ...
It seems you already use 'form', then what I did is: views.py: if request.method == "POST": form = MyForm(request.
Read more >How to Work with AJAX in Django - Pluralsight
To make the guide more interactive, we will use a real-time example to demonstrate the POST and GET AJAX requests in Django.
Read more >How to send Django form with AJAX - DEV Community
To create and save an object in a single step, we are using the create() method. Let's take a look our html form...
Read more >Send the data with a POST request with an inlineformset ...
In principle I have two forms in a createview (ModelForm and ... action: function () { $.ajax({ url: url, type: 'POST', data: parameters, ......
Read more >Django forms with Ajax | How to use ajax with django - YouTube
If you want to see a jquery version, below is the link to the like ... ajax request, django ajax post, django ajax...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

Ok, chaps, sorry for the long delay, I couldn’t get to the computer.
Anyways, I think this turned out to be pretty easy problem (or am I this naive?). Here it goes:
I don’t know if this is the desired result for @olivierdalang , however this works in the following way:
yours truly,
this looks like an interesting problem. I’ll try tackling it, probably during the night.
cheers, m.