The difference between get and filter in Django ORM

Source: Internet
Author: User

the difference between get and filter in a Django ORM:

It was previously assumed that the difference between get and filter was simply that filter returned more than one record, while get only supported a single recording until the related_name Attribute to find that the difference is much more than that, the most essential difference is

the value returned by filter is a queryset object,

get   The return value is a defined model

Use Get The returned results go to access the child Table object successfully, while using the Filter It's going to go wrong.

650) this.width=650, "width=" 554 "height=" "src="/e/u261/themes/default/images/spacer.gif "style=" Background:url ( "/e/u261/themes/default/images/word.gif") no-repeat center;border:1px solid #ddd; "alt=" Spacer.gif "/>

is because the Queryset object does not have a realtaed_name property and cannot be traced back to the child table


The difference between get and filter in Django ORM

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.