2014-08-12 20:08:40 +08:00
|
|
|
import decimal
|
|
|
|
|
|
|
|
from django.db import models
|
|
|
|
|
|
|
|
|
|
|
|
class Cash(decimal.Decimal):
|
|
|
|
currency = 'USD'
|
|
|
|
|
|
|
|
|
|
|
|
class CashField(models.DecimalField):
|
|
|
|
def __init__(self, **kwargs):
|
|
|
|
kwargs['max_digits'] = 20
|
|
|
|
kwargs['decimal_places'] = 2
|
2017-01-21 21:13:44 +08:00
|
|
|
super().__init__(**kwargs)
|
2014-08-12 20:08:40 +08:00
|
|
|
|
2017-07-07 01:18:05 +08:00
|
|
|
def from_db_value(self, value, expression, connection):
|
2014-08-12 20:08:40 +08:00
|
|
|
cash = Cash(value)
|
|
|
|
cash.vendor = connection.vendor
|
|
|
|
return cash
|
|
|
|
|
|
|
|
|
|
|
|
class CashModel(models.Model):
|
|
|
|
cash = CashField()
|