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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T17:47:12+00:00 2026-05-26T17:47:12+00:00

(Using django as an example; the ForeignKey is implicit in the example) >>> from

  • 0

(Using django as an example; the ForeignKey is implicit in the example)

>>> from coconuts.models import Coconut, Swallow
>>> c1 = Coconut.objects.get(id=1)
>>> s = Swallow.objects.get(id=1)
>>> c2 = s.coconuts_carried.filter(id=1)
>>> c1 == c2
True
>>> c1 is c2
False

My understanding is that ‘is’ tests identity, while == tests equality. In this case, c1 and c2 are the same exact object. Why “isn’t” they the same thing?

  • 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-05-26T17:47:13+00:00Added an answer on May 26, 2026 at 5:47 pm

    is compares python objects, not objects in your database. each query returns a new python objects, and so c and c2 are different.

    to see this, try changing some of the properties of c or c2. Only one of them will change.

    as can be seen from the docs,

    c == c2
    

    is equivalent to

    c.id == c2.id
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Snippet taken from this question from django.db.models import F ... MyModel.objects.filter(id=...).update(hit_count=F(hit_count)+1) It was suggested
I have a simple question. using the example from django above. How can i
I'm using the python-openid library from Janrain at http://openidenabled.com/python-openid/ I adapted their Django example
Using Django's built in models, how would one create a triple-join between three models.
Using Django 1.1, I am trying to select the maximum value from a varchar
I am currently using Django to construct JSON encoded objects which a retrieved using
Is there a GUI tool using which I can design new Django models graphically?
I'm using server side processing as per the Django example in DataTables . I
Manual example: http://docs.djangoproject.com/en/1.0/topics/forms/formsets/#formset-validation (I'm using Django 1.0.3 to run on Google App Engine) Code:
I'm using the very cool django-filter (via: http://github.com/alex/django-filter ) and either can't seem to

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.