In django how to check whether any entry exists for a query
sc=scorm.objects.filter(Header__id=qp.id)
This was how it was done in php
if(mysql_num_rows($resultn)) {
// True condition
}
else {
// False condition
}
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You can use
exists():Older versions: (<1.2)
Use
count():The advantage over e.g.
len()is, that the QuerySet is not yet evaluated:Having this in mind, When QuerySets are evaluated can be worth reading.
If you use
get(), e.g.scorm.objects.get(pk=someid), and the object does not exists, anObjectDoesNotExistexception is raised: