Top "Django-orm" questions

Django's ORM system, comprising its queryset and model systems.

How to perform OR condition in django queryset?

I want to write a Django query equivalent to this SQL query: SELECT * from user where income >= 5000 or income …

python sql django django-queryset django-orm
Django values_list vs values

In Django, what's the difference between the following two: Article.objects.values_list('comment_id', flat=True).distinct() vs Article.…

django django-models django-queryset django-orm
What's the difference between select_related and prefetch_related in Django ORM?

In Django doc, select_related() "follows" foreign-key relationships, selecting additional related-object data when it executes its query. prefetch_related() does …

python django django-models django-orm
Django database query: How to get object by id?

Django automatically creates an id field as primary key. Now I need to get the object by this id. object = …

django django-models django-orm
Select DISTINCT individual columns in django?

I'm curious if there's any way to do a query in Django that's not a "SELECT * FROM..." underneath. I'm trying …

django django-models distinct django-queryset django-orm
Django: List field in model?

In my model, I want a field that has a list of triplets. e.g. [[1, 3, 4], [4, 2, 6], [8, 12, 3], [3, 3, 9]]. Is there a field that …

django django-orm
Select distinct values from a table field

I'm struggling getting my head around the Django's ORM. What I want to do is get a list of distinct …

django django-queryset django-orm query-performance
Chaining multiple filter() in Django, is this a bug?

I always assumed that chaining multiple filter() calls in Django was always the same as collecting them in a single …

django django-orm
How to create an object for a Django model with a many to many field?

My model: class Sample(models.Model): users = models.ManyToManyField(User) I want to save both user1 and user2 in that …

python django django-models django-orm
How to view corresponding SQL query of the Django ORM's queryset?

Is there a way I can print the query the Django ORM is generating? Say I execute the following statement: …

django django-models django-orm