Вычисляемые поля из других классов - PullRequest
0 голосов
/ 29 апреля 2019

Я пытаюсь рассчитать ежемесячный доход с использованием среднемесячного дохода от модели продуктов, месячной сезонности из модели сезонности продуктов и ежемесячного увеличения по модели Capacity RamUp - они рассчитываются в модели доходов.

Я получаю следующую ошибку - неподдерживаемые типы операндов для *: '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 

Я пытаюсь рассчитать ежемесячный доход, используя средний ежемесячный доход

...