python - Expected type 'int', got 'IntegerField' instead Django -
i trying object of class guide value of calculation of other objects in class. how far have got in code got error
expected type 'int', got 'integerfield' instead.
how work?
here code:
class guide(models.model): guide_title = models.charfield(max_length=200) guide_category = models.charfield(max_length=70) guide_why = models.textfield() guide_how = models.textfield() user_current_conversion_rate = models.integerfield(default=0) user_optimal_conversion_rate = models.integerfield(default=0) user_monthly_visitors = models.integerfield(default=0) user_average_order_value = models.integerfield(default=0) user_increase_conversion_rate = models.integerfield(default=0) @property def user_increase_conversion_rate(self): return int( (self.user_monthly_visitors*(self.user_optimal_conversion_rate/100))* self.user_average_order_value) - ((self.user_monthly_visitors*(self.user_current_conversion_rate/100))* self.user_average_order_value)
if need handling on field via @property
, can change field name add underscore (by convention) , write property getter , setter methods. way django cleanly knows how set field, , control on how gets set.
see:
https://www.stavros.io/posts/how-replace-django-model-field-property/
Comments
Post a Comment