How to add form field dynamically?

59 views
Skip to first unread message

Django Lover

unread,
Sep 26, 2018, 7:46:14 AM9/26/18
to Django users
I am creating a model form, i need to add a field dynamically can you please give me the solution by using your sharp intelligence? 

synm.png


Product/service are coming from the model field.they are not static.


Add New is unlimited.



please help


Joel

unread,
Sep 26, 2018, 8:01:48 AM9/26/18
to django...@googlegroups.com
Describe what you mean by add dynamically. If blocks in templates allow a great deal of flexibility. 

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/f144ae51-a036-4aeb-94d5-d058a4067489%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Django Lover

unread,
Sep 26, 2018, 8:31:24 AM9/26/18
to Django users
Hi joel Thank for response.

I want something like this-

form.png










1- when I click on add row button a new Row (No-2) will create dynamically.
2- In the select product/service its an options dropdown. the option should have related model data(from table product and service list)
3-  when i save all records in the dynamic field save to the database.


I hope it clear to you. but if you need more information please let me know i am glad to discuss with you.

:)

Joel

unread,
Sep 26, 2018, 8:44:07 AM9/26/18
to django...@googlegroups.com
I don't think django alone can help you here. You need to do that with JavaScript.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.

Django Lover

unread,
Sep 26, 2018, 9:55:21 AM9/26/18
to Django users
Then What is the solution please let HELP ME?? I know that it will done by Jquery but how? I dont Know

Joel Mathew

unread,
Sep 26, 2018, 12:02:52 PM9/26/18
to django...@googlegroups.com
You would use jquery to create the button using the $(selector).html(code).
Since this doesnt fall within the scope of this django group, I wont elaborate. If you know basic javascript and jquery, it should be easy.



matteo gassend (LanguageMatt)

unread,
Sep 26, 2018, 12:47:30 PM9/26/18
to django...@googlegroups.com
You could always mix jquery with formsets

Kasper Laudrup

unread,
Sep 26, 2018, 1:58:53 PM9/26/18
to django...@googlegroups.com
Hi Django Lover,

On 26/09/2018 15.55, Django Lover wrote:
> Then What is the solution please let HELP ME?? I know that it will done
> by Jquery but how? I dont Know
>
>

The first hit I got on a search for "jquery dynamic form" sent me to
this page:

https://www.jqueryscript.net/tags.php?/dynamic%20form/

Looks like something like this:

https://www.jqueryscript.net/form/Dynamic-Form-Creation-Deletion.html

is exactly what you need?

Of course you still need to handle the submitted form on the server
(Django) side and you might not be able to use most of Djangos builtin
form handling functionality, but someone else definitely knows more
about that than me.

Kind regards,

Kasper Laudrup

Devender Kumar

unread,
Oct 1, 2018, 11:39:14 AM10/1/18
to django...@googlegroups.com
Hi,
I have been to this type of problem.
There two solutions to this
You have to made this using java script for front end and for database or backend.
For front end make a counter which will create a form fileds with name="columnname$countet" sir that the post request you can fetch all the detail in the backend
You can have two approaches for backend.
One to make a table and for each add store a reference two which thing it belongs  to 
Like there is one question and there can be any no of ans two that question. In senerios like this make a question model and in answer model with foreign key to question table in this senerio u will have one question can have any no of answer

Second approach which I followed is to store the form data to JSON.
Enjoy
Thanks


--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.

heriberto ochoa

unread,
Oct 1, 2018, 12:51:35 PM10/1/18
to Django users
Reply all
Reply to author
Forward
0 new messages