help with creating checkbox form

17 views
Skip to first unread message

Tosin Ayoola

unread,
Mar 3, 2020, 6:46:10 AM3/3/20
to django...@googlegroups.com
Good day guyz,
i'm working on  a project that requires user making multiple selections using checkbox after which these selected item get save to the database after click on the on submit i've research on this and can't find any help, i have it on html and javascript but i need the selected item saved to database, can any one help me out, pls it urgent ?

Kasper Laudrup

unread,
Mar 3, 2020, 7:39:23 AM3/3/20
to django...@googlegroups.com
Hi Tosin,
I assume you have already followed the Django tutorial to get a grasp of
the basics. Then have a look here:

https://docs.djangoproject.com/en/3.0/topics/forms/

to implement what you need and feel free to ask any specific questions
you might have.

Kind regards,

Kasper Laudrup

MH

unread,
Mar 3, 2020, 8:01:31 AM3/3/20
to Django users
Hi

I got something like this to work with
var_selection = forms.MultipleChoiceField(required=False, widget=forms.CheckboxSelectMultiple, choices=a_list_that_i_prepared_previously,)

Tosin Ayoola

unread,
Mar 3, 2020, 8:40:49 AM3/3/20
to django...@googlegroups.com
thanks for the response but django doc still doesn't explain or help much, pls see attached file, the project allows user select list of services they want, by clicking on  the checkbox(something like selecting multiple mails in your mail account), i have it already in html and Js to sum the price up but i need these selected services to be saved to the db, now my question is it how do i do that using django

--
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/fb8a51a9-fd86-d4f4-85aa-c3dd888f301c%40stacktrace.dk.
Screenshot from 2020-03-03 12-39-54.png
Screenshot from 2020-03-03 12-41-12.png

MH

unread,
Mar 3, 2020, 8:59:48 AM3/3/20
to Django users
Dear Tosin

In my html template I used
<form method="post">{% csrf_token %}
        {{ form.as_p }}
       
<input type="submit" value="Assign">

and in my views.py in the corresponding view I have a section where I check if the method is POST:
if request.method == 'POST':

Later I do this:
var_list_of_checked_boxes = request.POST.getlist('var_selection')


Reply all
Reply to author
Forward
0 new messages