feat: base增加PositiveDecimalField
This commit is contained in:
parent
a31aa7e337
commit
5498d98e38
|
@ -1,5 +1,9 @@
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from rest_framework import serializers
|
from rest_framework import serializers
|
||||||
|
from django.db.models import DecimalField
|
||||||
|
from django.core.validators import MinValueValidator
|
||||||
|
from django.utils.functional import cached_property
|
||||||
|
from decimal import Decimal
|
||||||
|
|
||||||
|
|
||||||
class MyFilePathField(serializers.CharField):
|
class MyFilePathField(serializers.CharField):
|
||||||
|
@ -8,3 +12,9 @@ class MyFilePathField(serializers.CharField):
|
||||||
if 'http' in value:
|
if 'http' in value:
|
||||||
return str(value)
|
return str(value)
|
||||||
return settings.BASE_URL + str(value)
|
return settings.BASE_URL + str(value)
|
||||||
|
|
||||||
|
class PositiveDecimalField(DecimalField):
|
||||||
|
|
||||||
|
@cached_property
|
||||||
|
def validators(self):
|
||||||
|
return [MinValueValidator(Decimal('0.0'))] + super().validators
|
Loading…
Reference in New Issue