Top "Django-orm" questions

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

How to use custom manager with related objects?

I have a custom manager. I want to use it for related objects. I found use_for_related_fields in …

django django-managers django-orm
django - Get the set of objects from Many To One relationship

Please have a look at these models: class Album(models.Model): user = models.ForeignKey(User) name = models.CharField(max_length=200) …

django django-models django-views django-orm
How to define default data for Django Models?

I want my application to have default data such as user types. What's the most efficient way to manage default …

django django-models django-orm django-migrations
prefetch_related for multiple Levels

If my Models look like: class Publisher(models.Model): pass class Book(models.Model): publisher = models.ForeignKey(Publisher) class Page(…

django django-queryset django-orm
How to properly query a ManyToManyField for all the objects in a list (or another ManyToManyField)?

I'm rather stumped about the best way to build a Django query that checks if all the elements of a …

django django-queryset django-orm
Django and Aggregate: Sum of distinct values?

I am trying to do a django aggregate function, but am unable to produce the desired result. What I've got: …

django django-orm
Example of what SQLAlchemy can do, and Django ORM cannot

I've been doing a lot of research lately into using Pyramid with SQLAlchemy versus keeping a current application in Django. …

python sqlalchemy django-orm
How to execute a GROUP BY ... COUNT or SUM in Django ORM?

Prologue: This is a question arising often in SO: Django Models Group By Django equivalent for count and group by …

python django group-by django-orm
Optimizing database queries in Django REST framework

I have the following models: class User(models.Model): name = models.Charfield() email = models.EmailField() class Friendship(models.Model): from_…

python django-rest-framework django-queryset django-orm django-select-related
--fake-initial vs --fake in Django migration?

What is the difference between --fake-initial and --fake in Django migrations? What are the dangers of using fake migrations? Anybody …

django django-models django-orm django-migrations