Answer the question
In order to leave comments, you need to log in
How to optimize image queries in Django model?
There are such models:
class Product(models.Model):
name = models.CharField()
color_variant_of = models.ForeignKey('self', blank=True, null=True, related_name="color_variants", verbose_name='Вариант цвета')
class ProductColor(models.Model):
name = models.CharField()
hex_name = models.CharField()
class ProductInfo(models.Models):
product = models.OneToOneField(Product)
color = models.ForeignKey(ProductColor)
class ProductImage(models.Model):
product = models.ForeignKey(ProductColor)
image = models.ImageField()
Answer the question
In order to leave comments, you need to log in
prefetch_related
And yes, prefetch_related can be customized so that it does not fetch everything
First of all, it's a strange structure.
Firstly, why make a separate Product info model if they still have a 1k1 connection? Move fields from ProductInfo to Product.
Use Select_related first , then you can use prefetch related.
If it doesn’t help (well, you never know), you can do monkey patching
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question