django - Looping checkbox not all values adding to database -
I have the following function, what should it do, which should loop the submitted values in the checkbox named Group, then Each value is in the database. However it seems to add a value to the database, is there a mess?
Groups = 1,3,3,4 Function Renewed Post Works: Form: forms.py When you submit a form like this, the parameter may look like this: Definition of your form; On the other hand, defining groups as a I think that you would be better if you defined
def Add_batch (requested): # If we find a post, then get request post value. If we have valid data before saving to request.method == 'POST': form = batchform (request.POST) # to check if form.is_valid (): # Clear all data and add to var data. Data = form.cleaned_data group = data ['group']. Batch = batch (content = data ['message'], group = group.bizzets.jet (pk = item), user = request.user) batch. Save () returns for items in groups (","): Redirect (batch.jet_send_conformation_page),
Groups 1, 3, 4 < / Pre>
form action = "{% url 'add_batch'%}" method = "post" square = "form-horizontal" Encrypt = "Multipart / Form-Data" & gt; {% For items in% groups} & lt; Label class = "groups" & gt; & Lt; Input type = "checkbox" name = "group" value = "{{item.id}}" /> {{Item.name}} & lt; Br / & gt; & Lt; / Labels & gt; {% Endfor%} & lt; / Form & gt;
class batchform (forms.Form): groups = forms. Defragment (max_length = 100)
? Groups = 1 and group = 3 and group = 4
CharField The code will be populated with the value derived from the request.GET ['group'] , which will receive only one value.
groups like:
CHOICES = ((0, '1'), (1 , '2'), (2, '3'),) Class MyForm (forms.Form): groups = forms.MultipleChoiceField (option = choice, label = "group", required = false)
Comments
Post a Comment