Skip to content

n+1 queries for ListModelMixin in rest_framework.mixins #9448

Discussion options

You must be logged in to vote

As I said, it depends. As an example, let's take the models from the Django tutorial:

# models.py
import datetime
from django.db import models
from django.utils import timezone


class Question(models.Model):
    question_text = models.CharField(max_length=200)
    pub_date = models.DateTimeField("date published")

    def __str__(self):
        return self.question_text

    def was_published_recently(self):
        now = timezone.now()
        return now - datetime.timedelta(days=1) <= self.pub_date <= now


class Choice(models.Model):
    question = models.ForeignKey(
        Question, 
        on_delete=models.CASCADE,
        related_name="choices",
    )
    choice_text = models.Cha…

Replies: 1 comment 3 replies

Comment options

You must be logged in to vote
3 replies
@Pradeep713
Comment options

@browniebroke
Comment options

Answer selected by Pradeep713
@Pradeep713
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants