Can anyone told me how to prevent to store blank input field of multiple input in Django Models












1















In my form there are multiple input field means there are two fieldset in which same input fields are available and i want to store both that input into models in different ids. It is working but when i filled only one input field and click on submit button then the second one is also stored blank but i want to prevent it. It's means that i only want to store filled input field into model and blank one will not not stored.



My Form.html



 <form class="well form-horizontal" method="post" action="{% url 'fixed_doclist' %}">
{% csrf_token %}
<fieldset>
<div class="form-group">
<label class="col-md-4 control-label">Document Name</label>
<div class="col-md-6 inputGroupContainer">
<div class="input-group"><span class="input-group-addon"><i class="glyphicon glyphicon-user"></i></span><input id="fullName" name="dname" placeholder="Full Name" class="form-control" value="" type="text"></div>
</div>
</div>

<div class="form-group">
<label class="col-md-4 control-label">Exp Date</label>
<div class="col-md-6 inputGroupContainer">
<div class="input-group"><span class="input-group-addon"><i class="glyphicon glyphicon-home"></i></span><input id="postcode" name="exp" placeholder="Postal Code/ZIP" class="form-control" value="" type="text"></div>
</div>
</div>
<div class="form-group">
<label class="col-md-4 control-label">Renewal Date</label>
<div class="col-md-6 inputGroupContainer">
<div class="input-group"><span class="input-group-addon"><i class="glyphicon glyphicon-home"></i></span><input id="postcode" name="renewdt" placeholder="Postal Code/ZIP" class="form-control" value="" type="text"></div>
</div>
</div>
<div class="form-group">
<label class="col-md-4 control-label">Purpose</label>
<div class="col-md-6 inputGroupContainer">
<div class="input-group"><span class="input-group-addon"><i class="glyphicon glyphicon-home"></i></span><input id="state" name="purpose" placeholder="State/Province/Region" class="form-control" value="" type="text"></div>
</div>
</div>

<div class="form-group">
<label class="col-md-4 control-label">Remarks</label>
<div class="col-md-6 inputGroupContainer">
<div class="input-group"><span class="input-group-addon"><i class="glyphicon glyphicon-envelope"></i></span><input id="email" name="remark" placeholder="Email" class="form-control" value="" type="text"></div>
</div>
</div>
</fieldset><br/><br/>



<fieldset>
<div class="form-group">
<label class="col-md-4 control-label">Document Name</label>
<div class="col-md-6 inputGroupContainer">
<div class="input-group"><span class="input-group-addon"><i class="glyphicon glyphicon-user"></i></span><input id="fullName" name="dname1" placeholder="Full Name" class="form-control" value="" type="text"></div>
</div>
</div>

<div class="form-group">
<label class="col-md-4 control-label">Exp Date</label>
<div class="col-md-6 inputGroupContainer">
<div class="input-group"><span class="input-group-addon"><i class="glyphicon glyphicon-home"></i></span><input id="postcode" name="exp1" placeholder="Postal Code/ZIP" class="form-control" value="" type="text"></div>
</div>
</div>
<div class="form-group">
<label class="col-md-4 control-label">Renewal Date</label>
<div class="col-md-6 inputGroupContainer">
<div class="input-group"><span class="input-group-addon"><i class="glyphicon glyphicon-home"></i></span><input id="postcode" name="renewdt1" placeholder="Postal Code/ZIP" class="form-control" value="" type="text"></div>
</div>
</div>
<div class="form-group">
<label class="col-md-4 control-label">Purpose</label>
<div class="col-md-6 inputGroupContainer">
<div class="input-group"><span class="input-group-addon"><i class="glyphicon glyphicon-home"></i></span><input id="state" name="purpose1" placeholder="State/Province/Region" class="form-control" value="" type="text"></div>
</div>
</div>

<div class="form-group">
<label class="col-md-4 control-label">Remarks</label>
<div class="col-md-6 inputGroupContainer">
<div class="input-group"><span class="input-group-addon"><i class="glyphicon glyphicon-envelope"></i></span><input id="email" name="remark1" placeholder="Email" class="form-control" value="" type="text"></div>
</div>
</div>
</fieldset>

<button>Submit</button>
</form>


View.py File



def fixed_doclist(request):
print("Form is submitted successfully!")
dname = request.POST.get("dname", False)
exp = request.POST.get("exp", False)
renewdt = request.POST.get("renewdt", False)
purpose = request.POST.get("purpose", False)
remark = request.POST.get("remark", False)

dname1 = request.POST.get("dname1", False)
exp1 = request.POST.get("exp1", False)
renewdt1 = request.POST.get("renewdt1", False)
purpose1 = request.POST.get("purpose1", False)
remark1 = request.POST.get("remark1", False)

DocFixed = Doc.objects.bulk_create([Doc(dname = dname, exp = exp, renewdt = renewdt, purpose = purpose, remark = remark),Doc(dname = dname1, exp = exp1, renewdt = renewdt1, purpose = purpose1, remark = remark1)])

return render(request,'fixeddoclist.html')


Model.Py File



class Doc(models.Model):
dname = models.CharField(max_length=20)
exp = models.CharField(max_length=10)
renewdt = models.CharField(max_length=50)
purpose = models.CharField(max_length=20)
remark = models.CharField(max_length=10)

def __str__(self):
return self.dname









share|improve this question























  • Are you saying that you only want to create a Doc instance if all fields for that Document are provided?

    – Will Keeling
    Nov 22 '18 at 12:00











  • yes Sir @Will Keeling

    – Abhishek Kumar
    Nov 23 '18 at 7:08
















1















In my form there are multiple input field means there are two fieldset in which same input fields are available and i want to store both that input into models in different ids. It is working but when i filled only one input field and click on submit button then the second one is also stored blank but i want to prevent it. It's means that i only want to store filled input field into model and blank one will not not stored.



My Form.html



 <form class="well form-horizontal" method="post" action="{% url 'fixed_doclist' %}">
{% csrf_token %}
<fieldset>
<div class="form-group">
<label class="col-md-4 control-label">Document Name</label>
<div class="col-md-6 inputGroupContainer">
<div class="input-group"><span class="input-group-addon"><i class="glyphicon glyphicon-user"></i></span><input id="fullName" name="dname" placeholder="Full Name" class="form-control" value="" type="text"></div>
</div>
</div>

<div class="form-group">
<label class="col-md-4 control-label">Exp Date</label>
<div class="col-md-6 inputGroupContainer">
<div class="input-group"><span class="input-group-addon"><i class="glyphicon glyphicon-home"></i></span><input id="postcode" name="exp" placeholder="Postal Code/ZIP" class="form-control" value="" type="text"></div>
</div>
</div>
<div class="form-group">
<label class="col-md-4 control-label">Renewal Date</label>
<div class="col-md-6 inputGroupContainer">
<div class="input-group"><span class="input-group-addon"><i class="glyphicon glyphicon-home"></i></span><input id="postcode" name="renewdt" placeholder="Postal Code/ZIP" class="form-control" value="" type="text"></div>
</div>
</div>
<div class="form-group">
<label class="col-md-4 control-label">Purpose</label>
<div class="col-md-6 inputGroupContainer">
<div class="input-group"><span class="input-group-addon"><i class="glyphicon glyphicon-home"></i></span><input id="state" name="purpose" placeholder="State/Province/Region" class="form-control" value="" type="text"></div>
</div>
</div>

<div class="form-group">
<label class="col-md-4 control-label">Remarks</label>
<div class="col-md-6 inputGroupContainer">
<div class="input-group"><span class="input-group-addon"><i class="glyphicon glyphicon-envelope"></i></span><input id="email" name="remark" placeholder="Email" class="form-control" value="" type="text"></div>
</div>
</div>
</fieldset><br/><br/>



<fieldset>
<div class="form-group">
<label class="col-md-4 control-label">Document Name</label>
<div class="col-md-6 inputGroupContainer">
<div class="input-group"><span class="input-group-addon"><i class="glyphicon glyphicon-user"></i></span><input id="fullName" name="dname1" placeholder="Full Name" class="form-control" value="" type="text"></div>
</div>
</div>

<div class="form-group">
<label class="col-md-4 control-label">Exp Date</label>
<div class="col-md-6 inputGroupContainer">
<div class="input-group"><span class="input-group-addon"><i class="glyphicon glyphicon-home"></i></span><input id="postcode" name="exp1" placeholder="Postal Code/ZIP" class="form-control" value="" type="text"></div>
</div>
</div>
<div class="form-group">
<label class="col-md-4 control-label">Renewal Date</label>
<div class="col-md-6 inputGroupContainer">
<div class="input-group"><span class="input-group-addon"><i class="glyphicon glyphicon-home"></i></span><input id="postcode" name="renewdt1" placeholder="Postal Code/ZIP" class="form-control" value="" type="text"></div>
</div>
</div>
<div class="form-group">
<label class="col-md-4 control-label">Purpose</label>
<div class="col-md-6 inputGroupContainer">
<div class="input-group"><span class="input-group-addon"><i class="glyphicon glyphicon-home"></i></span><input id="state" name="purpose1" placeholder="State/Province/Region" class="form-control" value="" type="text"></div>
</div>
</div>

<div class="form-group">
<label class="col-md-4 control-label">Remarks</label>
<div class="col-md-6 inputGroupContainer">
<div class="input-group"><span class="input-group-addon"><i class="glyphicon glyphicon-envelope"></i></span><input id="email" name="remark1" placeholder="Email" class="form-control" value="" type="text"></div>
</div>
</div>
</fieldset>

<button>Submit</button>
</form>


View.py File



def fixed_doclist(request):
print("Form is submitted successfully!")
dname = request.POST.get("dname", False)
exp = request.POST.get("exp", False)
renewdt = request.POST.get("renewdt", False)
purpose = request.POST.get("purpose", False)
remark = request.POST.get("remark", False)

dname1 = request.POST.get("dname1", False)
exp1 = request.POST.get("exp1", False)
renewdt1 = request.POST.get("renewdt1", False)
purpose1 = request.POST.get("purpose1", False)
remark1 = request.POST.get("remark1", False)

DocFixed = Doc.objects.bulk_create([Doc(dname = dname, exp = exp, renewdt = renewdt, purpose = purpose, remark = remark),Doc(dname = dname1, exp = exp1, renewdt = renewdt1, purpose = purpose1, remark = remark1)])

return render(request,'fixeddoclist.html')


Model.Py File



class Doc(models.Model):
dname = models.CharField(max_length=20)
exp = models.CharField(max_length=10)
renewdt = models.CharField(max_length=50)
purpose = models.CharField(max_length=20)
remark = models.CharField(max_length=10)

def __str__(self):
return self.dname









share|improve this question























  • Are you saying that you only want to create a Doc instance if all fields for that Document are provided?

    – Will Keeling
    Nov 22 '18 at 12:00











  • yes Sir @Will Keeling

    – Abhishek Kumar
    Nov 23 '18 at 7:08














1












1








1








In my form there are multiple input field means there are two fieldset in which same input fields are available and i want to store both that input into models in different ids. It is working but when i filled only one input field and click on submit button then the second one is also stored blank but i want to prevent it. It's means that i only want to store filled input field into model and blank one will not not stored.



My Form.html



 <form class="well form-horizontal" method="post" action="{% url 'fixed_doclist' %}">
{% csrf_token %}
<fieldset>
<div class="form-group">
<label class="col-md-4 control-label">Document Name</label>
<div class="col-md-6 inputGroupContainer">
<div class="input-group"><span class="input-group-addon"><i class="glyphicon glyphicon-user"></i></span><input id="fullName" name="dname" placeholder="Full Name" class="form-control" value="" type="text"></div>
</div>
</div>

<div class="form-group">
<label class="col-md-4 control-label">Exp Date</label>
<div class="col-md-6 inputGroupContainer">
<div class="input-group"><span class="input-group-addon"><i class="glyphicon glyphicon-home"></i></span><input id="postcode" name="exp" placeholder="Postal Code/ZIP" class="form-control" value="" type="text"></div>
</div>
</div>
<div class="form-group">
<label class="col-md-4 control-label">Renewal Date</label>
<div class="col-md-6 inputGroupContainer">
<div class="input-group"><span class="input-group-addon"><i class="glyphicon glyphicon-home"></i></span><input id="postcode" name="renewdt" placeholder="Postal Code/ZIP" class="form-control" value="" type="text"></div>
</div>
</div>
<div class="form-group">
<label class="col-md-4 control-label">Purpose</label>
<div class="col-md-6 inputGroupContainer">
<div class="input-group"><span class="input-group-addon"><i class="glyphicon glyphicon-home"></i></span><input id="state" name="purpose" placeholder="State/Province/Region" class="form-control" value="" type="text"></div>
</div>
</div>

<div class="form-group">
<label class="col-md-4 control-label">Remarks</label>
<div class="col-md-6 inputGroupContainer">
<div class="input-group"><span class="input-group-addon"><i class="glyphicon glyphicon-envelope"></i></span><input id="email" name="remark" placeholder="Email" class="form-control" value="" type="text"></div>
</div>
</div>
</fieldset><br/><br/>



<fieldset>
<div class="form-group">
<label class="col-md-4 control-label">Document Name</label>
<div class="col-md-6 inputGroupContainer">
<div class="input-group"><span class="input-group-addon"><i class="glyphicon glyphicon-user"></i></span><input id="fullName" name="dname1" placeholder="Full Name" class="form-control" value="" type="text"></div>
</div>
</div>

<div class="form-group">
<label class="col-md-4 control-label">Exp Date</label>
<div class="col-md-6 inputGroupContainer">
<div class="input-group"><span class="input-group-addon"><i class="glyphicon glyphicon-home"></i></span><input id="postcode" name="exp1" placeholder="Postal Code/ZIP" class="form-control" value="" type="text"></div>
</div>
</div>
<div class="form-group">
<label class="col-md-4 control-label">Renewal Date</label>
<div class="col-md-6 inputGroupContainer">
<div class="input-group"><span class="input-group-addon"><i class="glyphicon glyphicon-home"></i></span><input id="postcode" name="renewdt1" placeholder="Postal Code/ZIP" class="form-control" value="" type="text"></div>
</div>
</div>
<div class="form-group">
<label class="col-md-4 control-label">Purpose</label>
<div class="col-md-6 inputGroupContainer">
<div class="input-group"><span class="input-group-addon"><i class="glyphicon glyphicon-home"></i></span><input id="state" name="purpose1" placeholder="State/Province/Region" class="form-control" value="" type="text"></div>
</div>
</div>

<div class="form-group">
<label class="col-md-4 control-label">Remarks</label>
<div class="col-md-6 inputGroupContainer">
<div class="input-group"><span class="input-group-addon"><i class="glyphicon glyphicon-envelope"></i></span><input id="email" name="remark1" placeholder="Email" class="form-control" value="" type="text"></div>
</div>
</div>
</fieldset>

<button>Submit</button>
</form>


View.py File



def fixed_doclist(request):
print("Form is submitted successfully!")
dname = request.POST.get("dname", False)
exp = request.POST.get("exp", False)
renewdt = request.POST.get("renewdt", False)
purpose = request.POST.get("purpose", False)
remark = request.POST.get("remark", False)

dname1 = request.POST.get("dname1", False)
exp1 = request.POST.get("exp1", False)
renewdt1 = request.POST.get("renewdt1", False)
purpose1 = request.POST.get("purpose1", False)
remark1 = request.POST.get("remark1", False)

DocFixed = Doc.objects.bulk_create([Doc(dname = dname, exp = exp, renewdt = renewdt, purpose = purpose, remark = remark),Doc(dname = dname1, exp = exp1, renewdt = renewdt1, purpose = purpose1, remark = remark1)])

return render(request,'fixeddoclist.html')


Model.Py File



class Doc(models.Model):
dname = models.CharField(max_length=20)
exp = models.CharField(max_length=10)
renewdt = models.CharField(max_length=50)
purpose = models.CharField(max_length=20)
remark = models.CharField(max_length=10)

def __str__(self):
return self.dname









share|improve this question














In my form there are multiple input field means there are two fieldset in which same input fields are available and i want to store both that input into models in different ids. It is working but when i filled only one input field and click on submit button then the second one is also stored blank but i want to prevent it. It's means that i only want to store filled input field into model and blank one will not not stored.



My Form.html



 <form class="well form-horizontal" method="post" action="{% url 'fixed_doclist' %}">
{% csrf_token %}
<fieldset>
<div class="form-group">
<label class="col-md-4 control-label">Document Name</label>
<div class="col-md-6 inputGroupContainer">
<div class="input-group"><span class="input-group-addon"><i class="glyphicon glyphicon-user"></i></span><input id="fullName" name="dname" placeholder="Full Name" class="form-control" value="" type="text"></div>
</div>
</div>

<div class="form-group">
<label class="col-md-4 control-label">Exp Date</label>
<div class="col-md-6 inputGroupContainer">
<div class="input-group"><span class="input-group-addon"><i class="glyphicon glyphicon-home"></i></span><input id="postcode" name="exp" placeholder="Postal Code/ZIP" class="form-control" value="" type="text"></div>
</div>
</div>
<div class="form-group">
<label class="col-md-4 control-label">Renewal Date</label>
<div class="col-md-6 inputGroupContainer">
<div class="input-group"><span class="input-group-addon"><i class="glyphicon glyphicon-home"></i></span><input id="postcode" name="renewdt" placeholder="Postal Code/ZIP" class="form-control" value="" type="text"></div>
</div>
</div>
<div class="form-group">
<label class="col-md-4 control-label">Purpose</label>
<div class="col-md-6 inputGroupContainer">
<div class="input-group"><span class="input-group-addon"><i class="glyphicon glyphicon-home"></i></span><input id="state" name="purpose" placeholder="State/Province/Region" class="form-control" value="" type="text"></div>
</div>
</div>

<div class="form-group">
<label class="col-md-4 control-label">Remarks</label>
<div class="col-md-6 inputGroupContainer">
<div class="input-group"><span class="input-group-addon"><i class="glyphicon glyphicon-envelope"></i></span><input id="email" name="remark" placeholder="Email" class="form-control" value="" type="text"></div>
</div>
</div>
</fieldset><br/><br/>



<fieldset>
<div class="form-group">
<label class="col-md-4 control-label">Document Name</label>
<div class="col-md-6 inputGroupContainer">
<div class="input-group"><span class="input-group-addon"><i class="glyphicon glyphicon-user"></i></span><input id="fullName" name="dname1" placeholder="Full Name" class="form-control" value="" type="text"></div>
</div>
</div>

<div class="form-group">
<label class="col-md-4 control-label">Exp Date</label>
<div class="col-md-6 inputGroupContainer">
<div class="input-group"><span class="input-group-addon"><i class="glyphicon glyphicon-home"></i></span><input id="postcode" name="exp1" placeholder="Postal Code/ZIP" class="form-control" value="" type="text"></div>
</div>
</div>
<div class="form-group">
<label class="col-md-4 control-label">Renewal Date</label>
<div class="col-md-6 inputGroupContainer">
<div class="input-group"><span class="input-group-addon"><i class="glyphicon glyphicon-home"></i></span><input id="postcode" name="renewdt1" placeholder="Postal Code/ZIP" class="form-control" value="" type="text"></div>
</div>
</div>
<div class="form-group">
<label class="col-md-4 control-label">Purpose</label>
<div class="col-md-6 inputGroupContainer">
<div class="input-group"><span class="input-group-addon"><i class="glyphicon glyphicon-home"></i></span><input id="state" name="purpose1" placeholder="State/Province/Region" class="form-control" value="" type="text"></div>
</div>
</div>

<div class="form-group">
<label class="col-md-4 control-label">Remarks</label>
<div class="col-md-6 inputGroupContainer">
<div class="input-group"><span class="input-group-addon"><i class="glyphicon glyphicon-envelope"></i></span><input id="email" name="remark1" placeholder="Email" class="form-control" value="" type="text"></div>
</div>
</div>
</fieldset>

<button>Submit</button>
</form>


View.py File



def fixed_doclist(request):
print("Form is submitted successfully!")
dname = request.POST.get("dname", False)
exp = request.POST.get("exp", False)
renewdt = request.POST.get("renewdt", False)
purpose = request.POST.get("purpose", False)
remark = request.POST.get("remark", False)

dname1 = request.POST.get("dname1", False)
exp1 = request.POST.get("exp1", False)
renewdt1 = request.POST.get("renewdt1", False)
purpose1 = request.POST.get("purpose1", False)
remark1 = request.POST.get("remark1", False)

DocFixed = Doc.objects.bulk_create([Doc(dname = dname, exp = exp, renewdt = renewdt, purpose = purpose, remark = remark),Doc(dname = dname1, exp = exp1, renewdt = renewdt1, purpose = purpose1, remark = remark1)])

return render(request,'fixeddoclist.html')


Model.Py File



class Doc(models.Model):
dname = models.CharField(max_length=20)
exp = models.CharField(max_length=10)
renewdt = models.CharField(max_length=50)
purpose = models.CharField(max_length=20)
remark = models.CharField(max_length=10)

def __str__(self):
return self.dname






django






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 22 '18 at 7:56









Abhishek KumarAbhishek Kumar

87




87













  • Are you saying that you only want to create a Doc instance if all fields for that Document are provided?

    – Will Keeling
    Nov 22 '18 at 12:00











  • yes Sir @Will Keeling

    – Abhishek Kumar
    Nov 23 '18 at 7:08



















  • Are you saying that you only want to create a Doc instance if all fields for that Document are provided?

    – Will Keeling
    Nov 22 '18 at 12:00











  • yes Sir @Will Keeling

    – Abhishek Kumar
    Nov 23 '18 at 7:08

















Are you saying that you only want to create a Doc instance if all fields for that Document are provided?

– Will Keeling
Nov 22 '18 at 12:00





Are you saying that you only want to create a Doc instance if all fields for that Document are provided?

– Will Keeling
Nov 22 '18 at 12:00













yes Sir @Will Keeling

– Abhishek Kumar
Nov 23 '18 at 7:08





yes Sir @Will Keeling

– Abhishek Kumar
Nov 23 '18 at 7:08












1 Answer
1






active

oldest

votes


















0














Since you only want to create a Doc instance if all fields are provided, it should just be a case of checking that something is set for all fields. Since you might not have data for both Doc instances, you wouldn't need to bulk create.



For example:



def fixed_doclist(request):
print("Form is submitted successfully!")

doc_args = {
dname: request.POST.get("dname", False),
exp: request.POST.get("exp", False),
renewdt: request.POST.get("renewdt", False),
purpose: request.POST.get("purpose", False),
remark: request.POST.get("remark", False)
}

doc1_args = {
dname: request.POST.get("dname1", False),
exp: request.POST.get("exp1", False),
renewdt: request.POST.get("renewdt1", False),
purpose: request.POST.get("purpose1", False),
remark: request.POST.get("remark1", False)
}

if all(doc_args.values()):
Doc.objects.create(**doc_args)

if all(doc1_args.values()):
Doc.objects.create(**doc1_args)

return render(request,'fixeddoclist.html')





share|improve this answer
























  • Thank You @Will Keeling. I'll update you once I'll check.

    – Abhishek Kumar
    Nov 23 '18 at 12:36











  • It's shows a error like name 'dname' is not defined in doc_args.

    – Abhishek Kumar
    Nov 24 '18 at 6:06













  • Error is solved. Now It's working fine according to my rquirements.

    – Abhishek Kumar
    Nov 24 '18 at 8:08











  • ok. I did that @Will Keeling

    – Abhishek Kumar
    Nov 24 '18 at 9:17











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53426232%2fcan-anyone-told-me-how-to-prevent-to-store-blank-input-field-of-multiple-input-i%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









0














Since you only want to create a Doc instance if all fields are provided, it should just be a case of checking that something is set for all fields. Since you might not have data for both Doc instances, you wouldn't need to bulk create.



For example:



def fixed_doclist(request):
print("Form is submitted successfully!")

doc_args = {
dname: request.POST.get("dname", False),
exp: request.POST.get("exp", False),
renewdt: request.POST.get("renewdt", False),
purpose: request.POST.get("purpose", False),
remark: request.POST.get("remark", False)
}

doc1_args = {
dname: request.POST.get("dname1", False),
exp: request.POST.get("exp1", False),
renewdt: request.POST.get("renewdt1", False),
purpose: request.POST.get("purpose1", False),
remark: request.POST.get("remark1", False)
}

if all(doc_args.values()):
Doc.objects.create(**doc_args)

if all(doc1_args.values()):
Doc.objects.create(**doc1_args)

return render(request,'fixeddoclist.html')





share|improve this answer
























  • Thank You @Will Keeling. I'll update you once I'll check.

    – Abhishek Kumar
    Nov 23 '18 at 12:36











  • It's shows a error like name 'dname' is not defined in doc_args.

    – Abhishek Kumar
    Nov 24 '18 at 6:06













  • Error is solved. Now It's working fine according to my rquirements.

    – Abhishek Kumar
    Nov 24 '18 at 8:08











  • ok. I did that @Will Keeling

    – Abhishek Kumar
    Nov 24 '18 at 9:17
















0














Since you only want to create a Doc instance if all fields are provided, it should just be a case of checking that something is set for all fields. Since you might not have data for both Doc instances, you wouldn't need to bulk create.



For example:



def fixed_doclist(request):
print("Form is submitted successfully!")

doc_args = {
dname: request.POST.get("dname", False),
exp: request.POST.get("exp", False),
renewdt: request.POST.get("renewdt", False),
purpose: request.POST.get("purpose", False),
remark: request.POST.get("remark", False)
}

doc1_args = {
dname: request.POST.get("dname1", False),
exp: request.POST.get("exp1", False),
renewdt: request.POST.get("renewdt1", False),
purpose: request.POST.get("purpose1", False),
remark: request.POST.get("remark1", False)
}

if all(doc_args.values()):
Doc.objects.create(**doc_args)

if all(doc1_args.values()):
Doc.objects.create(**doc1_args)

return render(request,'fixeddoclist.html')





share|improve this answer
























  • Thank You @Will Keeling. I'll update you once I'll check.

    – Abhishek Kumar
    Nov 23 '18 at 12:36











  • It's shows a error like name 'dname' is not defined in doc_args.

    – Abhishek Kumar
    Nov 24 '18 at 6:06













  • Error is solved. Now It's working fine according to my rquirements.

    – Abhishek Kumar
    Nov 24 '18 at 8:08











  • ok. I did that @Will Keeling

    – Abhishek Kumar
    Nov 24 '18 at 9:17














0












0








0







Since you only want to create a Doc instance if all fields are provided, it should just be a case of checking that something is set for all fields. Since you might not have data for both Doc instances, you wouldn't need to bulk create.



For example:



def fixed_doclist(request):
print("Form is submitted successfully!")

doc_args = {
dname: request.POST.get("dname", False),
exp: request.POST.get("exp", False),
renewdt: request.POST.get("renewdt", False),
purpose: request.POST.get("purpose", False),
remark: request.POST.get("remark", False)
}

doc1_args = {
dname: request.POST.get("dname1", False),
exp: request.POST.get("exp1", False),
renewdt: request.POST.get("renewdt1", False),
purpose: request.POST.get("purpose1", False),
remark: request.POST.get("remark1", False)
}

if all(doc_args.values()):
Doc.objects.create(**doc_args)

if all(doc1_args.values()):
Doc.objects.create(**doc1_args)

return render(request,'fixeddoclist.html')





share|improve this answer













Since you only want to create a Doc instance if all fields are provided, it should just be a case of checking that something is set for all fields. Since you might not have data for both Doc instances, you wouldn't need to bulk create.



For example:



def fixed_doclist(request):
print("Form is submitted successfully!")

doc_args = {
dname: request.POST.get("dname", False),
exp: request.POST.get("exp", False),
renewdt: request.POST.get("renewdt", False),
purpose: request.POST.get("purpose", False),
remark: request.POST.get("remark", False)
}

doc1_args = {
dname: request.POST.get("dname1", False),
exp: request.POST.get("exp1", False),
renewdt: request.POST.get("renewdt1", False),
purpose: request.POST.get("purpose1", False),
remark: request.POST.get("remark1", False)
}

if all(doc_args.values()):
Doc.objects.create(**doc_args)

if all(doc1_args.values()):
Doc.objects.create(**doc1_args)

return render(request,'fixeddoclist.html')






share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 23 '18 at 12:09









Will KeelingWill Keeling

11.9k22635




11.9k22635













  • Thank You @Will Keeling. I'll update you once I'll check.

    – Abhishek Kumar
    Nov 23 '18 at 12:36











  • It's shows a error like name 'dname' is not defined in doc_args.

    – Abhishek Kumar
    Nov 24 '18 at 6:06













  • Error is solved. Now It's working fine according to my rquirements.

    – Abhishek Kumar
    Nov 24 '18 at 8:08











  • ok. I did that @Will Keeling

    – Abhishek Kumar
    Nov 24 '18 at 9:17



















  • Thank You @Will Keeling. I'll update you once I'll check.

    – Abhishek Kumar
    Nov 23 '18 at 12:36











  • It's shows a error like name 'dname' is not defined in doc_args.

    – Abhishek Kumar
    Nov 24 '18 at 6:06













  • Error is solved. Now It's working fine according to my rquirements.

    – Abhishek Kumar
    Nov 24 '18 at 8:08











  • ok. I did that @Will Keeling

    – Abhishek Kumar
    Nov 24 '18 at 9:17

















Thank You @Will Keeling. I'll update you once I'll check.

– Abhishek Kumar
Nov 23 '18 at 12:36





Thank You @Will Keeling. I'll update you once I'll check.

– Abhishek Kumar
Nov 23 '18 at 12:36













It's shows a error like name 'dname' is not defined in doc_args.

– Abhishek Kumar
Nov 24 '18 at 6:06







It's shows a error like name 'dname' is not defined in doc_args.

– Abhishek Kumar
Nov 24 '18 at 6:06















Error is solved. Now It's working fine according to my rquirements.

– Abhishek Kumar
Nov 24 '18 at 8:08





Error is solved. Now It's working fine according to my rquirements.

– Abhishek Kumar
Nov 24 '18 at 8:08













ok. I did that @Will Keeling

– Abhishek Kumar
Nov 24 '18 at 9:17





ok. I did that @Will Keeling

– Abhishek Kumar
Nov 24 '18 at 9:17




















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53426232%2fcan-anyone-told-me-how-to-prevent-to-store-blank-input-field-of-multiple-input-i%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

"Incorrect syntax near the keyword 'ON'. (on update cascade, on delete cascade,)

Alcedinidae

Origin of the phrase “under your belt”?