Django.core.exceptions.FieldError: Unknown field(s) (field_name) specified for ModelName

As stated in my title I am getting error:

django.core.exceptions.FieldError: Unknown field(s) (total_price) specified for CERequest

In admin panel everything works fine and it is displayed correctly but when I am trying to open html page with my form I get this error.

Can you please let me know how to fix this error and how can I pass the total_price method to my form.

models.py

class CostRequest(models.Model):
    related_component = models.ForeignKey(CostCalculator, on_delete=models.CASCADE, default=1, blank=True)
    related_product = models.ForeignKey(Product, on_delete=models.CASCADE, null=True, blank=True, related_name='related_product_ce_request')
    number_of_units = models.IntegerField(default=0)

    @property
    def total_price(self):
        return self.related_component.rate.hourly_rate * self.number_of_units

forms.py

class CalculatorForm(forms.ModelForm):
    number_of_units = forms.IntegerField(min_value=0)
    
    class Meta: 
        model = CERequest
        fields = ('related_product', 'related_component', 'number_of_units', 'total_price') # 'total_price here causes issues
Back to Top