How to invoke Sub Form which have MULTIPLE OPTIONS to choose inside Django Form.

43 views
Skip to first unread message

Sai

unread,
May 21, 2020, 12:30:13 AM5/21/20
to Django users
Hi Everyone, 
I am pretty much familiar with Django Forms with models. I want to build a Submit Form which consists of attributes like UserName, Email, address field and 3 options to select the packages, for example, Basic, Standard, and Advanced.  I have gone through Django Docs but there is no such thing.

Please let me know how to achieve this and open to ideas. 

Thank You in Advance.

Vishesh Mangla

unread,
May 21, 2020, 1:23:13 AM5/21/20
to django...@googlegroups.com

#template

<select id="cars" name="carlist" form="carform">
  <option value="volvo">Volvo</option>
  <option value="saab">Saab</option>
  <option value="opel">Opel</option>
  <option value="audi">Audi</option>
</select>

 

<form class=”f1” style=”display:none;” method=>

</form>

 

 

<form class=”f2” style=”display:none;” method=>

</form>

<form class=”f3” style=”display:none;” method=>

</form>

<script>

Document.querySelector(“select”).addEventListener(“change”,(ele)={

If ele.target.textContent ==”Volvo”:

    ..

Else if

...

Else

...

})

</script>

 

Otherwise just send a form to pick the user preference out of Basic, Standard, Advanced, get the request and based on the request’s attributes send a form back through redirect function.

Sent from Mail for Windows 10

--
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 view this discussion on the web visit https://groups.google.com/d/msgid/django-users/cb12fc88-0d5a-4ec4-a6d6-1272a0a69d9a%40googlegroups.com.

 

chaitanya orakala

unread,
May 21, 2020, 1:50:01 AM5/21/20
to django...@googlegroups.com
Thank you for your response. I see some javascript inside the form. I am not fully aware of it. is there any template which I can use in forms??

Devansh Chaubey

unread,
May 21, 2020, 2:05:25 AM5/21/20
to django...@googlegroups.com
Hey Chaitanya ,
You can do something like this 
In the models.py 
CHOICES=[('Basic','Basic'), ('Standard','Standard'), ('Advanced','Advanced')] class Modelname(models.Model): pack=models.CharField(max_length=12,choices=CHOICES,blank=True) Forms.py class Formname(forms.ModelForm): class meta: model=modelname fields=(pack,name,email)
widgets = { 'pack':forms.radioselect() }




chaitanya orakala

unread,
May 21, 2020, 3:00:27 AM5/21/20
to django...@googlegroups.com
wow... thanks Devansh. It was simple and easy to understand and no extra hassle to add new language into the code.

chaitanya orakala

unread,
May 22, 2020, 4:21:19 PM5/22/20
to django...@googlegroups.com
Hello Djangians, 
   I have a select drop-down list in a form. whenever I will select an option, it should pop-up a list containing information about the package.
Please suggest how to achieve this. 
Thank You
Reply all
Reply to author
Forward
0 new messages