i have these models
class Theme(models.Model):
name = models.charfield()
class Category(models.Model):
name = models.charfield()
class Product(models.Model):
name = models.charfield()
.........
class MstProduct(Product):
category = models.ForeignField(Category, related_name = 'category_products')
themes = models.ManyToManyField(Theme, related_name='theme_products')
.........
i want to fetch categories and there related products by
Category.objects.prefetch_related('category_products').select_related('category_products__themes')
is this is the right way to do this?
source https://stackoverflow.com/questions/73178385/is-this-is-the-right-way-to-use-prefetch-related
Comments
Post a Comment