Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

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.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 736705
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T07:38:10+00:00 2026-05-14T07:38:10+00:00

In django how to check whether any entry exists for a query sc=scorm.objects.filter(Header__id=qp.id) This

  • 0

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
    }
  • 1 1 Answer
  • 1 View
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T07:38:10+00:00Added an answer on May 14, 2026 at 7:38 am

    You can use exists():

    if scorm.objects.filter(Header__id=qp.id).exists():
        ....
    

    Returns True if the QuerySet contains any results, and False if not. This tries to perform the query in the simplest and fastest way possible, but it does execute nearly the same query as a normal QuerySet query.

    Older versions: (<1.2)

    Use count():

    sc=scorm.objects.filter(Header__id=qp.id)
    
    if sc.count() > 0:
       ...
    

    The advantage over e.g. len() is, that the QuerySet is not yet evaluated:

    count() performs a SELECT COUNT(*) behind the scenes, so you should always use count() rather than loading all of the record into Python objects and calling len() on the result.

    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, an ObjectDoesNotExist exception is raised:

    from django.core.exceptions import ObjectDoesNotExist
    try:
        sc = scorm.objects.get(pk=someid)
    except ObjectDoesNotExist:
        print ...
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How can I order by descending my query set in django by date? Reserved.objects.all().filter(client=client_id).order_by('check_in')
According to this SO post: How to check the TEMPLATE_DEBUG flag in a django
How do I check whether an object already exists, and only add it if
Is there any way to check if command exists? I know that I can
If this is the view in Django_notification (https://github.com/pinax/django-notification/blob/master/notification/views.py), how do I display the check
When I define a Django form class similar to this: def class MyForm(forms.Form): check
Using django, which is the way to check if data is present? I know
I have 2 forms in my Django view. How can I do a check
So I have installed Django on my FreeBSD 8.2 box like this: pip install
Right now, if I want to check whether the current page is accessed through

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.