2011-10-20 69 views
0

我已經通過這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(),它給我的只有蔬菜的價格?而不是獲得糖果和水果的所有價格數據?

謝謝!

回答

0

你是不是應該由vegetablefruitssweets布爾字段,而不是plus來過濾你的經理,這是場我甚至不模型中看到了什麼?

class VegManager(models.Manager): 
    def get_query_set(self): 
     return super(VegManager, self).get_query_set().filter(vegetables=True) 

class FruitsManager(models.Manager): 
    def get_query_set(self): 
     return super(FruitsManager, self).get_query_set().filter(fruits=True) 

class SweetsManager(models.Manager): 
    def get_query_set(self): 
     return super(SweetsManager, self).get_query_set().filter(sweets=True)