I have a model with 3 fields namely name
, qualification
and keyskills
. The keyskills
field is given input as comma separated values, e.g "c,c++,java"
, the name
from a text box and qualification
from a dropdown menu.
I want to display the keyskills
to be stored in a separate row in the database. I have done it. However, when I give input with one empty value, for example, "c,c++,,java"
, the database should not accept the empty value in between – it should move on to the next value "java"
instead.
My models.py
class form1(models.Model):
name=models.CharField(max_length=20)
qualification=models.CharField(max_length=20)
keyskills=models.CharField(max_length=50)
def __unicode__(self):
return self.name,self.qualification,self.key
views.py
def formdisplay(request):
if request.method=='POST':
i1=request.POST.get("input1")
i2=request.POST.get("drop1")
i3=request.POST.get("input2")
var=i3.split(",")
for i in var:
form1(name=i1,qualification=i2,keyskills=i).save()
return HttpResponseRedirect('/formdisplay')
else:
return render(request,"formdisplay.html"
formdisplay.html
<html>
<head>
</head>
<body>
<form action="." method="post">{% csrf_token %}
<input type="text" name="input1">
<select name="drop1">
<option>B.E cse</option>
<option>B.E ece</option>
<option>B.E eee</option>
</select>
<input type="text" name="input2">
<input type="submit" value="save">
</form>
</body>
</html>