我已經通過這https://docs.djangoproject.com/en/1.1/ref/models/querysets/#values-fields 但我的要求是不同的。從django模型中選擇列出的字段
我有一個商店模型定製經理:
class VegManager(models.Manager):
def get_query_set(self):
return super(VegManager, self).get_query_set().filter(plus=True)
class FruitsManager(models.Manager):
def get_query_set(self):
return super(FruitsManager, self).get_query_set().filter(plus=True)
class SweetsManager(models.Manager):
def get_query_set(self):
return super(SweetsManager, self).get_query_set().filter(plus=True)
class Store(models.Model):
vegetable = models.BooleanField()
veg1_price = models.DecimalField(max_digits=6, decimal_places=2, null=True, blank=True)
veg2_price = models.DecimalField(max_digits=6, decimal_places=2, null=True, blank=True)
veg3_price = models.DecimalField(max_digits=6, decimal_places=2, null=True, blank=True)
fruits = models.BoolearnField()
fruit1_price = models.DecimalField(max_digits=6, decimal_places=2, null=True, blank=True)
fruit2_price = models.DecimalField(max_digits=6, decimal_places=2, null=True, blank=True)
fruit3_price = models.DecimalField(max_digits=6, decimal_places=2, null=True, blank=True)
sweets = models.BooleanField()
sweet1_price = models.DecimalField(max_digits=6, decimal_places=2, null=True, blank=True)
sweet2_price = models.DecimalField(max_digits=6, decimal_places=2, null=True, blank=True)
sweet3_price = models.DecimalField(max_digits=6, decimal_places=2, null=True, blank=True)
objects = models.Manager()
v = VegManager()
f = FruitsManager()
s = SweetsManager()
class Veg(Store):
class Meta:
proxy = True
class Froots(Store):
class Meta:
proxy = True
class Sweet(Store):
class Meta:
proxy = True
有什麼辦法,如果我sweets.v.all()
,它給我的只有蔬菜的價格?而不是獲得糖果和水果的所有價格數據?
謝謝!
感謝,這似乎是一個簡單的方法。 – user993563