Float field question

Hi everyone
Just a silly question. How can I retrieve value from models. floatfiled and make operations?

Example

F1 = models.FloatField ()
F2 = models.FloatField (default = 3.765)
F3 = models.FloatField ()

Not working
Python will redefine variable

F1 = 5.788

Not working

F1 = F2 + F3

Not working anything like
F2.value

I have to get float valus from some Models, make some operation as a float And stor it again in another model as floafied

Thanks a lot for suggestions

You don’t retrieve the value from a model. The model is just the template. You retrieve values from instances of the model.

If you would please provide more details of the code you’re trying to run, in the context in which you’re running it, we might be able to provide more tangible assistance.

Hi Ken thanks for quick answer.
(i know difference from a class and his instance)

for a moment i thought was possible to do that

class mymodel (models.Model):
     val1 = models.FloatField ()
     val2 = models.FloatField ()
     val3 = models.FloatField ()
     val3 = val2 - val1

but correct way should be something like
( if you kindly could confirm an correct )

class mymodel (models.Model):
     val1 = models.FloatField ()
     val2 = models.FloatField ()
     val3 = models.FloatField ()
     def save(self, *args, **kwargs):
         self.val3 = self.val2 - self.val1
         super().save(*args, **kwargs)

it’s 2 in the morning for me… i’m getting tired

thanks again for your help

1 Like

Yep, that’s the basic idea.