# update model form with json infomration

**URL:** https://forum.djangoproject.com/t/update-model-form-with-json-infomration/12543
**Category:** Forms & APIs
**Created:** [March 10, 2022, 4:02pm UTC](https://forum.djangoproject.com/t/update-model-form-with-json-infomration/12543 "2022-03-10T16:02:19Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![eyalyakir159](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/eyalyakir159/32/5532_2.png) [@eyalyakir159](https://forum.djangoproject.com/u/eyalyakir159)
#### Post date: [March 10, 2022, 4:02pm UTC](https://forum.djangoproject.com/t/update-model-form-with-json-infomration/12543/1 "2022-03-10T16:02:19Z")

</div>

hello everyone,  
i have mad a custom admin page using django forms.  
I have a form that I want to set values dynamicly using an exiting model that come via ajax request.

the html:

 {% csrf\_token %} 

שם הקורס {{course\_form.name}} 

```
                    <div class="input-con">
                        <span class="input-name">מספר קורס</span>
                        {{course_form.course_slug}}
                    </div>   
                </div>
                <div class="input_single">
                    <div class="input-con">
                        <span class="input-name">תיאור הקורס</span>
                        {{course_form.description}}
                    </div>
                </div>

                <div class="input_double">
                    <div class="input-con">
                        <span class="input-name">משפט מפתח</span>
                        {{course_form.title_description}}
                    </div>

                    <div class="input-con">
                        <span class="input-name">מחיר</span>
                        {{course_form.price}}
                    </div>   
                </div>

                <div class="input_double extra_margin">
                    
                    
                    <div class="input-con autor_selected">
                        <span class="input-name">שם היוצר</span>
                        <!--{{course_form.autor}}!-->
                        {{course_form.autor}}

                        <span class="input-name">מוכן להצגה</span>
                        <!--{{course_form.autor}}!-->
                        {{course_form.display}}

                    </div>   
                    <div class="input-con selected_div">
                        <span class="input-name">קורסים חוסמים</span>
                        {{course_form.blocked_by}}
                    </div>
                </div>

                <div class="full_width">
                    <div class="image_container">
                        <img style="background-image:url({% static 'main_website\images\graduation.png' %})" id="display_image" alt="">
                    </div>
                    <div class="input-con center_on_image">
                        {{course_form.image}}
                        <label for="upload"><i class="fas fa-upload"></i></label>
                    </div>

                    
                </div>

                <div class="full_width_button">
                    <button class="cta">
                        <span>עדכן פרטים</span>
                        <svg width="15px" height="10px" viewBox="0 0 13 10">
                            <path d="M11,5 L1,5"></path>
                            <polyline points="4 1 0 5 4 9"></polyline>
                        </svg>
                    </button>

                </div>

            </form>

```

 ![Screen Shot 2022-03-10 at 18.01.29](https://us1.discourse-cdn.com/flex026/uploads/djangoproject/original/2X/0/0646eb63e139946e24bdd8aa0c623aa360f7299c.png)  
i recive the information via ajax and i want to update the form (set the name and stuff), is there a django/ajax function to do so or do i need to make it be hand?

---

<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: [March 10, 2022, 4:04pm UTC](https://forum.djangoproject.com/t/update-model-form-with-json-infomration/12543/2 "2022-03-10T16:04:15Z")

</div>

For clarity, are you looking to update the **form** , or are you looking to update the **model** based upon the data submitted via AJAX?

---

<div class="post-metadata">

### Author: ![eyalyakir159](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/eyalyakir159/32/5532_2.png) [@eyalyakir159](https://forum.djangoproject.com/u/eyalyakir159)
#### Post date: [March 10, 2022, 4:17pm UTC](https://forum.djangoproject.com/t/update-model-form-with-json-infomration/12543/3 "2022-03-10T16:17:01Z")

</div>

to be honest for both of the.  
once i click a button, i request information about a spesefic model, retrive it with ajax and update the form with the model context. than the user needs to change it, and once he submits the form via ajax i need to reupdate it in the db.

thanks for the quick respone.

---

<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: [March 10, 2022, 4:53pm UTC](https://forum.djangoproject.com/t/update-model-form-with-json-infomration/12543/4 "2022-03-10T16:53:39Z")

</div>

Ok, so breaking this down into the sequence of events:

- User requests a page
- User clicks a button on the page
- JavaScript on the page submits an AJAX request
- Server returns a JSON Response
- JavaScript updates input fields (and possibly other data) on the page from that response
- User is able to edit the form.
- User clicks a _different_ button to submit the form.
- Server processes the submission.

Is this a correct summary?

---

<div class="post-metadata">

### Author: ![eyalyakir159](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/eyalyakir159/32/5532_2.png) [@eyalyakir159](https://forum.djangoproject.com/u/eyalyakir159)
#### Post date: [March 10, 2022, 5:06pm UTC](https://forum.djangoproject.com/t/update-model-form-with-json-infomration/12543/5 "2022-03-10T17:06:58Z")

</div>

I have done everything expect

- JavaScript updates input fields (and possibly other data) on the page from that response  
is there a “cool django way” to do it, or should i acsses each input one by one via js and update?

---

<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: [March 10, 2022, 5:09pm UTC](https://forum.djangoproject.com/t/update-model-form-with-json-infomration/12543/6 "2022-03-10T17:09:35Z")

</div>

Django isn’t involved _at all_ on the browser side with the dynamic updating of a page. That’s a process that **must** be done with JavaScript.

About the best that Django can do is to create the JSON object with a structure that facilitates the JavaScript doing the updating in the client.

---

<div class="post-metadata">

### Author: ![eyalyakir159](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/eyalyakir159/32/5532_2.png) [@eyalyakir159](https://forum.djangoproject.com/u/eyalyakir159)
#### Post date: [March 10, 2022, 5:14pm UTC](https://forum.djangoproject.com/t/update-model-form-with-json-infomration/12543/7 "2022-03-10T17:14:28Z")

</div>

i see, thanks so much for the help! you have helped me since i started and i really appreciate it!
