Skip to content

Commit

Permalink
LGA-1773-added min and max validators to MoneyIntervalDRFField so tha…
Browse files Browse the repository at this point in the history
…t it works with DRF 3.0
  • Loading branch information
jogilder committed Nov 8, 2022
1 parent b12fb34 commit 0c3fc7c
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions cla_common/money_interval/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,14 @@ class MoneyIntervalDRFField(DRFField):
type_label = "moneyIntervalDRFField"
form_field_class = MoneyIntervalField

def __init__(self, max_value=9999999999, min_value=0, *args, **kwargs):
kwargs.setdefault("validators", [])
if max_value is not None:
kwargs["validators"].append(validators.MaxValueValidator(max_value))
if min_value is not None:
kwargs["validators"].append(validators.MinValueValidator(min_value))
super(MoneyIntervalDRFField, self).__init__(*args, **kwargs)

def field_to_native(self, obj, field_name):

moneyIntervalField = getattr(obj, field_name)
Expand Down

0 comments on commit 0c3fc7c

Please sign in to comment.