Debian Codegraph @

tests/from_db_value/models.py

raw
1 import decimal
2
3 from django.db import models
4
5
6 class Cash(decimal.Decimal):
7 currency = "USD"
8
9
10 class CashField(models.DecimalField):
11 def __init__(self, **kwargs):
12 kwargs["max_digits"] = 20
13 kwargs["decimal_places"] = 2
14 super().__init__(**kwargs)
15
16 def from_db_value(self, value, expression, connection):
17 cash = Cash(value)
18 cash.vendor = connection.vendor
19 return cash
20
21
22 class CashModel(models.Model):
23 cash = CashField()