django DecimalField - how do I retrieve the value as a float? -


so never have used django's decimalfield option if had known how difficult serialize model data json result.

long story short, how float value decimalfield?

my model looks this:

class dailyreport(models.model):     earnings = models.decimalfield(max_digits=12, decimal_places=4)      def earnings_float(self):         return self.earnings.to_float() 

obviously there no to_float() method available, do instead?

below later addition:

this works:

class dailyreport(models.model):     earnings = models.decimalfield(max_digits=12, decimal_places=4)      def earnings_float(self):         return float(self.earnings) 

but seems complicated. i'm trying use django-rest-framework serializing, since i'm using rest-framework stuff in app generally. in particular case i'd transform , serialize data python lists , dictionaries , store them documents in mongo db via pymongo 3.

just cast decimalfield float:

def earnings_float(self):         return float(self.earnings) 

Comments

Popular posts from this blog

python - TypeError: start must be a integer -

c# - DevExpress RepositoryItemComboBox BackColor property ignored -

django - Creating multiple model instances in DRF3 -