Django ORM queryset on nested queries
NickName:rush Ask DateTime:2014-11-04T08:23:58

Django ORM queryset on nested queries

I can't figure out how the default Django ORM processes queries like:

Model.objects.filter(foreign__field=value)

Does it make a lookup on each row, or is it smart enough to resolve the foreign field id(s) with the target value?

Or is it cheaper to make it this way?

value_temp = Foreign.objects.get(field=value)
Model.objects.filter(foreign=value_temp)

Copyright Notice:Content Author:「rush」,Reproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/26725740/django-orm-queryset-on-nested-queries

More about “Django ORM queryset on nested queries” related questions

Django - Raw SQL Queries or Django QuerySet ORM

I know Django Object Relational Mapper (ORM) helps bridge the gap between the database and our code Performing raw queries. But I want to find out which is better - Raw SQL Queries or Django Quer...

Show Detail

Django ORM queryset on nested queries

I can't figure out how the default Django ORM processes queries like: Model.objects.filter(foreign__field=value) Does it make a lookup on each row, or is it smart enough to resolve the foreign fi...

Show Detail

Optimize Django Rest ORM queries

I a react front-end, django backend (used as REST back). I've inherited the app, and it loads all the user data using many Models and Serializes. It loads very slow. It uses a filter to query for a

Show Detail

Django: is it possible to perform queries on a cached QuerySet instead of querying the database?

I often need to cache results and perform ORM-like operations but with normal Python logic because I don't want the database to be hit due to performance issues. For this very reason I wonder if D...

Show Detail

Multijoin queries in Django

What's the best and/or fastest method of doing multijoin queries in Django using the ORM and QuerySet API?

Show Detail

how to get queryset from django orm create

i want to get queryset as a return value when i use the create in django orm newUserTitle = User_Title.objects.none() newUserTitle = newUserQuestTitle | newUserReviewTitle newUserTitle =

Show Detail

Django ORM queryset

I am learning about the Django ORM and how to make queries, Lets suppose i have two models class Company(models.Model): structure = IntegerField() class Customer(models.Model): created_at =

Show Detail

django to snowflake connection and running ORM queries

I am looking to shift out of Postgres to SnowFlake as some of my features require run time analysis which is faster in Snowflake. I could only get the Python connector API for Snowflake which would

Show Detail

Is Nested aggregate queries possible with Django queryset

I want to calculate the monthly based profit with the following models using django queryset methods. The tricky point is that I have a freightselloverride field in the order table. It overrides th...

Show Detail

Django ORM Nested query set counts isse

I am using Django ORM nested queries. Reference found here: https://docs.djangoproject.com/en/dev/ref/models/querysets/#in But when i count connection.queries its say 122, i am so surprised if...

Show Detail