I would add it as a custom model method - see: 
https://docs.djangoproject.com/es/1.9/topics/db/models/#model-methods

So, for example:

class Temperature(models.Model):
    user = models.ForeignKey(User, unique=False)
    celcius = models.FloatField(null=True, blank=True)
    
    def _get_fahrenheit(self):
        "Returns the temperature in Fahrenheit."
        return '%s' % (self.celcius * 1.8 + 32.0)
    fahrenheit = property(_get_fahrenheit)


On Tuesday, 26 April 2016 23:43:51 UTC+2, Vince wrote:
>
> I need to store and retrieve temperatures in a model.  I'd like to store 
> all the values in celsius.  However some users prefer to view the value in 
> fahrenheit.
> What is the recommended way to setup a model like this?  
>
> Perhaps manually convert the values in the view and on save?
> Or is it possible to use python properties in a model for saves, updates 
> and gets? 
> Or is some other practice preferred?
>
> class Temp(models.Model):
>     user = models.ForeignKey(User, unique=False)
>     temperature = models.FloatField(null=True, blank=True)
>
>
>
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/4908e6a5-2b55-4abe-8a44-03e174c06704%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to