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 8765701
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T16:21:18+00:00 2026-06-13T16:21:18+00:00

I have next model: class People(models.Model): name = models.CharField(max_length=100) lastname = models.CharField(max_length=100) In views.py

  • 0

I have next model:

class People(models.Model):
    name = models.CharField(max_length=100)
    lastname = models.CharField(max_length=100) 

In views.py

-When I try this one:

 if People.objects.get(id=my_id):
        o=People.objects.get(id=my_id)
        oh=o.name
    else:
        send_notification_to_add_that_id(my_id)

I get this:

People query matching does not exist. 

What I want is that Query the my_id in my People table, if there is a match with that record get the id, else trigger the send_notification_to_add_that_id method.
When first “if conditions” does not have such a record, i am getting above error. How to by pass this issue? What is the good approach to know existence of a record in a table ?

  • 1 1 Answer
  • 0 Views
  • 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-06-13T16:21:20+00:00Added an answer on June 13, 2026 at 4:21 pm

    It’s throwing an exception:

    If there are no results that match the query, get() will raise a DoesNotExist exception.

    so you need to handle it:

    try:
        People.objects.get(id=my_id)
    except People.DoesNotExist:
        send_notification_to_add_that_id(my_id)
    

    alternativly you could do

    people = People.objects.filter(id=my_id)
    if people.exists():
        person = people[0]
    

    as filter doesn’t raise an exception if there are no results – it simply returns an empty QuerySet but this runs the risk of returning more then one object, so it doesn’t make as much sense as the first example.

    As an aside, it makes more sense to call your model Person instead of People as that is what is being represented by your model or in the case of the DB, each row in your table.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have next model: class People(models.Model): name = models.CharField(max_length=100) lastname = models.CharField(max_length=100) class Salary(models.Model):
I have this model: class People(models.Model): name = models.CharField(max_length=128, db_index=True) friends = models.ManyToManyField('self') So
Possible Duplicate: Django get a model's fields I have next model: class People(models.Model): name
I have the following model: class CompanyReport(models.Model): company = models.CharField(max_length=300) desc = models.TextField() text
I have this model class messages(models.Model): status_choices = ( (u'read',u'read'), (u'unread',u'unread') ) user =
I have a model: class Cost(models.Model): project = models.ForeignKey(Project) cost = models.FloatField() date =
In a django application I have the following model: class Appointment(models.Model): #some other fields
developers! I can't understand next situation For Example I have model class Pg::City <
I have two models, Item and Bid class Item include Mongoid::Document field :name, type:
In Django application I have these models: class DLL(models.Model): prev = models.ForeignKey('self', related_name =

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.