如何存储多选选项数据库

时间:2013-05-06 06:13:51

标签: python django python-2.7 django-models django-views

我需要将多个选择选项数据存储到数据库中。我尝试使用它但只需要一个选项。我给出了下面的代码。

模板

<select name="qualification" multiple>
<option value="">Select</option>
<script type="text/javascript">
                var functional=new Array("Any Graduates","Any UnderGraduates","Any PostGraduates","BE/BTech/MCA","BE/BTech","MCA","Other");
                for(var i=0;i<functional.length;i++)
                    document.write("<option value=\""+functional[i]+"\">"+functional[i]+"</option>");
            </script>
</select>

models.py

class edu(models.Model):
    qualification = models.CharField(max_length=100)

views.py

def jobpost(request):
     if request.method=='POST':
     qualification=request.POST.get('qualification')
     s=edu(qualification=qualification)
     s.save()
     return HttpResponseRedirect

1 个答案:

答案 0 :(得分:0)

你可以尝试

qualification = request.POST.getlist('qualification')