I want to have checkboxes in my form.  For that I took the table field
as ManyToManyField. When the template renders the form as its models,
it correctly save the values  in database, but when I create the form
with same fields myself i templates, it does not save the values. I
don't know where I am going wrong.
My code is :

views.py->

def search(request):
    query =request.GET.get('q', '')
    field_list = Material.objects.all()
    if query:
                material =Material.objects.get(id=request.GET['q'])
                test = Test.objects.all().filter(material_id = query)
                if request.method=='POST':
                        form = JobForm(request.POST)
                        if form.is_valid():
                                cd = form.cleaned_data
                                site =cd['site']
                                test = request.POST.getlist('test')
                                type_of_work = cd['type_of_work']
                                profile = form.save(commit=False)
                                id = ClientJob.objects.aggregate(Max('job_no'))
                                maxid =id['job_no__max']
                                if maxid== None :
                                        maxid = 1
                                else:
                                        maxid = maxid + 1
                                profile.job_no = maxid
                                profile.client = request.user
                                profile.save()
                                form.save_m2m()
                                form.save()
                        return render_to_response('tcc/new_client_ok.html', 
{'form':
form,}, context_instance=RequestContext(request))
                else:
                        form = JobForm()
                        return render_to_response('tcc/search.html', {'form': 
form,"query":
query,"test":test,"material":material,"field_list":field_list},
context_instance=RequestContext(request))
    else:
                results = Material.objects.all()
                return 
render_to_response('tcc/tags.html',{'field_list':field_list},
context_instance=RequestContext(request))

------------------------------------------------------------------------------------------------------------------------------------------------------------------

search.html-->

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN">

<html lang="en">
<head>
    <title>Search{% if query %} Results{% endif %}</title>
</head>
<body>
  <h1>Search</h1>
 <select name="form" ONCHANGE="location =
this.options[this.selectedIndex].value;">
{% for field in field_list %}
  <option 
value="http://localhost/automation/tcc11_12/search/?q={{field.id}}";>{{field.name}}</option>
        {% endfor %}
</select>
    <form action="" method="post">
        {% csrf_token %}
{% if query %}  
    <h2>Tests for "{{ material.name}}":</h2>

        Name : {{ material.name}}<br>
        <label for="id_site">Site:</label></th><td><input type="text"
name="site" id="id_site" />
         <table>
                        <tr><th>check tests</th><th>Test
Name</th><th>Quantity</th><th>Costs</th></tr>
{% if test %}
      {% for tests in test %}
        
                        <tr><td><input type="checkbox" name="test" id="id_test"
/></td><td>{{tests.name }}</td><td align="center">{{tests.quantity
}}</td><td>{{tests.cost }}</td>

        {% endfor %}

       {% endif  %}
        
        </tr></table><br>
        
              </ul>
    {% else %}
      <p>No material found</p>
    {% endif %}<input type="submit" value="Submit"></form>
</body>
</html>

Please do point me out where I am going wrong.
Thank you.


-- 
Sandeep Kaur
E-Mail: [email protected]
Blog: sandymadaan.wordpress.com

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.

Reply via email to