计算其他类别的字段

时间:2019-04-29 05:17:59

标签: python django-models

我尝试使用“产品”模型的平均每月收入,“产品季节性”模型的每月季节性和“产能提升”模型的每月增加量来计算月收入-这些都是在“收入”模型中计算的。

我收到以下错误-*不支持的操作数类型:'DeferredAttribute'和'DeferredAttribute'

class Product(models.Model) :
        business_name = models.ForeignKey (BusinessDetails, on_delete=models.CASCADE)
        product_name = models.CharField (max_length = 50)
        product_description = models.CharField (max_length = 50)
        average_unit_price = models.FloatField(blank=True, null=True)
        average_quantity_per_month = models.FloatField(default=1.0)
        average_revenue_per_month = models.FloatField(blank=True)

        @property
        def _get_total(self):
            #functions to calculate whatever you want...
                return self.average_quantity_per_month * self.average_unit_price

        def save (self, *args, **kwargs):
                self.average_revenue_per_month = self._get_total
                super(Product, self).save(*args, **kwargs)

        def get_absolute_url(self):
                return reverse('businessplan:SeasonalityInput')

        def  __str__(self) :
                return self.product_name

class ProductSeasonality (models.Model) :
        Product_name = models.ForeignKey (Product, on_delete=models.CASCADE)
        seasonality_description = models.CharField (max_length = 50)
        month_1_seasonality =  models.FloatField(default=0.083)
        month_2_seasonality =  models.FloatField(default=0.083)
        month_3_seasonality =  models.FloatField(default=0.083)
        month_4_seasonality =  models.FloatField(default=0.083)
        month_5_seasonality =  models.FloatField(default=0.083)
        month_6_seasonality =  models.FloatField(default=0.083)
        month_7_seasonality =  models.FloatField(default=0.083)
        month_8_seasonality =  models.FloatField(default=0.083)
        month_9_seasonality =  models.FloatField(default=0.083)
        month_10_seasonality =  models.FloatField(default=0.083)
        month_11_seasonality =  models.FloatField(default=0.083)
        month_12_seasonality =  models.FloatField(default=0.083)


        def get_absolute_url(self):
                return reverse('businessplan:RampUpInput')

        def  __str__(self) :
                return self.seasonality_description


class CapacityRampUp (models.Model) :
        Product_name = models.ForeignKey (Product, on_delete=models.CASCADE)
        capacity_ramp_up_description = models.CharField (max_length = 50)
        month_1_ramp_up =  models.FloatField(default=1.0)
        month_2_ramp_up =  models.FloatField(default=1.0)
        month_3_ramp_up =  models.FloatField(default=1.0)
        month_4_ramp_up =  models.FloatField(default=1.0)
        month_5_ramp_up =  models.FloatField(default=1.0)
        month_6_ramp_up =  models.FloatField(default=1.0)
        month_7_ramp_up =  models.FloatField(default=1.0)
        month_8_ramp_up =  models.FloatField(default=1.0)
        month_9_ramp_up =  models.FloatField(default=1.0)
        month_10_ramp_up =  models.FloatField(default=1.0)
        month_11_ramp_up =  models.FloatField(default=1.0)
        month_12_ramp_up =  models.FloatField(default=1.0)


        def get_absolute_url(self):
                return reverse('businessplan:BusinessDetails')

        def  __str__(self) :
                return self.capacity_ramp_up_description


class Revenue (models.Model) :
        product_name  = models.CharField (max_length = 50, blank=True)
        month_1_evenue = models.FloatField(blank=True, null=True)
        month_2_revenue = models.FloatField(blank=True, null=True)
        average_revenue_per_month = models.ForeignKey(Product,on_delete=models.CASCADE)
        month_1_seasonality = models.ForeignKey(ProductSeasonality,on_delete=models.CASCADE, related_name='seasonality_month_1')
        month_2_seasonality = models.ForeignKey(ProductSeasonality, on_delete=models.CASCADE)
        month_1_ramp_up =models.ForeignKey(CapacityRampUp,on_delete=models.CASCADE, related_name='ramp_up_month1')
        month_2_ramp_up = models.ForeignKey(CapacityRampUp, on_delete=models.CASCADE)


        @property
        def _get_total_month_1_revenue(self):
                return Product.average_revenue_per_month * ProductSeasonality.month_1_seasonality * CapacityRampUp.month_1_ramp_up

        @property
        def _get_total_month_2_revenue(self):
                return Product.average_revenue_per_month * ProductSeasonality.month_2_seasonality * CapacityRampUp.month_2_ramp_up

        def save(self, *args, **kwargs):
                self.month_1_revenue = self._get_total_month_1_revenue
                self.month_2_revenue = self._get_total_month_2_revenue
                super(Revenue, self).save(*args, **kwargs)

        def get_absolute_url(self):
                return reverse('businessplan:BusinessDetails')

        def  __str__(self) :
                return self.product_name 

我试图使用平均每月收入来计算每月收入

0 个答案:

没有答案