Django : select_related with ManyToManyField

前端 未结 2 1762
一生所求
一生所求 2021-02-12 06:33

I have :

class Award(models.Model) :
    name = models.CharField(max_length=100, db_index=True)

class Alias(models.Model) :
    awards = models.ManyToManyField(         


        
2条回答
  •  被撕碎了的回忆
    2021-02-12 06:48

    Django versions 1.4 and above have prefetch_related for this purpose.

    The prefetch_related method is similar to select_related, but does not do a database join. Instead, it executes additional database queries and does the joining in Python.

提交回复
热议问题