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

please how can i convert Foreignkey value string to float ? in models.py 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 '),
        ('exploration/production','exploration/production'),
        ('developpement/production','developpement/production'),
        ('Exploitation','Exploitation'),
        )
    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:

thanks



Read more here: https://stackoverflow.com/questions/67396488/how-can-i-convert-str-to-float-the-value-of-foreignkey

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: