我是这个django数据库查询的新手。
如何将其转换为django queryset
SELECT prod.item_code_id, prod.name, price.SRP
FROM inventory_product prod, inventory_pricing price
WHERE prod.item_code_id = price.item_code_id
class Product(models.Model):
item_code_id = models.AutoField(primary_key=True)
name = models.CharField(max_length=255)
description = models.CharField(max_length=255)
category = models.ForeignKey(Category)
color = models.ForeignKey(Color)
brand = models.ForeignKey(Brand)
item_size = models.ForeignKey(ItemSize)
class Pricing(models.Model):
product_id = models.AutoField(primary_key=True)
item_code = models.ForeignKey(Product)
supplier = models.ForeignKey(Supplier)
SRP = models.DecimalField(max_digits=5, decimal_places=2)
答案 0 :(得分:0)
在您的示例中,Django ORM应该足够了。如果你发布模特会更好,但它看起来像是:
for prod in Product.objects.all():
price = Pricing.objects.get(item_code=prod)
print prod.pk, prod.name, price.SRP