how can i convert str to float (the value of foreignkey)

please how can i convert Foreignkey value string to float ? in i create a following code, the target is to get the value of foreingkey as float then use it to calculate the value of redevance.

class production(models.Model):
    nom= models.CharField(max_length=70, blank=False, null=True)
    choix_type = (
        ('','selectionner le type de projet '),
    forme_projet = models.CharField(max_length=50, default='', blank=False, null=True, choices=choix_type)
    quantite = models.FloatField(blank=False, null=True)
    prix = models.FloatField(blank=False, null=True)
    def __str__(self):
        return str(self.nom) if self.nom else ''

    def calcule_production(self):
        return self.prix * self.quantite

class redevance(models.Model):
production_projet = models.ForeignKey(production, on_delete=models.CASCADE, null=True, blank=False)
    cout_transport = models.FloatField(blank=False, null=True)
    cout_liquifaction = models.FloatField(blank=False, null=True)
    cout_separation = models.FloatField(blank=False, null=True)

    def calcule_cout(self):

        return (self.cout_transport + self.cout_liquifaction + self.cout_separation) - self.production_projet

type error

the error seems like this:


Read more here:

Content Attribution

This content was originally published by Maria Aicha at Recent Questions - Stack Overflow, and is syndicated here via their RSS feed. You can read the original post over there.

%d bloggers like this: