У меня есть эти модели
class Product(models.Model):
product_id = models.AutoField(primary_key=True)
product_name = models.CharField(max_length=255, null = False, unique=True)
product_title = models.CharField(max_length=255, null = True)
product_price = models.CharField(max_length = 255)
brand = models.ForeignKey(Brand, on_delete=models.SET_NULL, null=True)
product_type = models.ForeignKey(Product_type, on_delete=models.SET_NULL, null=True)
class Feature(models.Model):
feature_id = models.AutoField(primary_key=True)
feature_name = models.CharField(max_length=255, null = False)
product_type = models.ForeignKey(Product_type, on_delete=models.SET_NULL, null=True)
feature_has_value = models.CharField(choices=has_value_choice, max_length = 1, null = False)
class Product_feature(models.Model):
product_feature_id = models.AutoField(primary_key=True)
feature = models.ForeignKey(Feature, on_delete=models.SET_NULL, null=True)
product = models.ForeignKey(Product, on_delete=models.SET_NULL, null=True, related_name='product_feature')
product_feature_value = models.CharField(max_length=255, null = False)
Теперь, как я могу получить product_features из модели продукта? Я хочу сделать запрос вот так
SELECT p.*, f.* from product p, product_feature f where f.product_id = p.product_id ORDER BY P.product_type_id