mirror of
				https://github.com/django/django.git
				synced 2025-10-31 01:25:32 +00:00 
			
		
		
		
	Co-Authored-By: Mariusz Felisiak <felisiak.mariusz@gmail.com> Co-Authored-By: Hasan Ramezani <hasan.r67@gmail.com>
		
			
				
	
	
		
			24 lines
		
	
	
		
			481 B
		
	
	
	
		
			Python
		
	
	
	
	
	
			
		
		
	
	
			24 lines
		
	
	
		
			481 B
		
	
	
	
		
			Python
		
	
	
	
	
	
| 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
 | |
|         super().__init__(**kwargs)
 | |
| 
 | |
|     def from_db_value(self, value, expression, connection):
 | |
|         cash = Cash(value)
 | |
|         cash.vendor = connection.vendor
 | |
|         return cash
 | |
| 
 | |
| 
 | |
| class CashModel(models.Model):
 | |
|     cash = CashField()
 |