@@ -86,15 +86,23 @@ def __init__(self, required=True, default=None, label=None, validators=None, err
8686 self .default = default
8787 self .required = bool (required ) if self .default is None else False
8888 # Added validator for check on required field.
89+ self ._src_validators = validators
8990 self ._validators = ([RequiredValidator ()] if self .required else []) + (validators or [])[:]
9091
9192 # Make errors dict.
9293 messages = {}
94+ self ._src_messages = messages
9395 for cls in reversed (self .__class__ .__mro__ ):
9496 messages .update (getattr (cls , 'default_error_messages' , {}))
9597 messages .update (error_messages or {})
9698 self .error_messages = messages
9799
100+ def __deepcopy__ (self , memo = {}):
101+ return self .__class__ (
102+ required = self .required , default = self .default , label = self .label ,
103+ validators = self ._src_validators , error_messages = self ._src_messages
104+ )
105+
98106 def bind (self , field_name , parent ):
99107 """
100108 Initialization field name and parent instance .
@@ -378,6 +386,14 @@ def __init__(self, min_length=None, max_length=None, trim_whitespace=False, allo
378386 message = self .error_messages ['min_length' ].format (min_length = self .min_length )
379387 self .validators .append (MinLengthValidator (self .min_length , message = message ))
380388
389+ def __deepcopy__ (self , memo = {}):
390+ return self .__class__ (
391+ required = self .required , default = self .default , label = self .label ,
392+ validators = self ._src_validators , error_messages = self ._src_messages ,
393+ min_length = self .min_length , max_length = self .max_length ,
394+ trim_whitespace = self .trim_whitespace , allow_blank = self .allow_blank
395+ )
396+
381397 def run_validation (self , data = None ):
382398 """
383399 We check for an empty string here, so that it does not fall into subclasses in `.to_internal_value ()`.
@@ -458,6 +474,13 @@ def __init__(self, min_value=None, max_value=None, *args, **kwargs):
458474 message = self .error_messages ['max_value' ].format (max_value = self .max_value )
459475 self .validators .append (MaxValueValidator (self .max_value , message = message ))
460476
477+ def __deepcopy__ (self , memo = {}):
478+ return self .__class__ (
479+ required = self .required , default = self .default , label = self .label ,
480+ validators = self ._src_validators , error_messages = self ._src_messages ,
481+ min_value = self .min_value , max_value = self .max_value
482+ )
483+
461484 def to_internal_value (self , data ):
462485 """
463486 Data transformation to python object.
@@ -526,6 +549,13 @@ def __init__(self, min_value=None, max_value=None, *args, **kwargs):
526549 message = self .error_messages ['max_value' ].format (max_value = self .max_value )
527550 self .validators .append (MaxValueValidator (self .max_value , message = message ))
528551
552+ def __deepcopy__ (self , memo = {}):
553+ return self .__class__ (
554+ required = self .required , default = self .default , label = self .label ,
555+ validators = self ._src_validators , error_messages = self ._src_messages ,
556+ min_value = self .min_value , max_value = self .max_value
557+ )
558+
529559 def to_internal_value (self , data ):
530560 """
531561 Data transformation to python object.
@@ -713,6 +743,14 @@ def __init__(self, child=None, min_length=None, max_length=None, allow_empty=Fal
713743 message = self .error_messages ['min_length' ].format (min_length = self .min_length )
714744 self .validators .append (MinLengthValidator (self .min_length , message = message ))
715745
746+ def __deepcopy__ (self , memo = {}):
747+ return self .__class__ (
748+ required = self .required , default = self .default , label = self .label ,
749+ validators = self ._src_validators , error_messages = self ._src_messages ,
750+ child = self .child , min_length = self .min_length , max_length = self .max_length ,
751+ allow_empty = self .allow_empty
752+ )
753+
716754 def to_internal_value (self , data ):
717755 """
718756 Data transformation to python list object.
@@ -776,6 +814,13 @@ def __init__(self, format=None, input_format=None, *args, **kwargs):
776814 self .input_format = input_format
777815 super ().__init__ (* args , ** kwargs )
778816
817+ def __deepcopy__ (self , memo = {}):
818+ return self .__class__ (
819+ required = self .required , default = self .default , label = self .label ,
820+ validators = self ._src_validators , error_messages = self ._src_messages ,
821+ format = getattr (self , 'format' ), input_format = getattr (self , 'input_format' )
822+ )
823+
779824 def to_internal_value (self , data ):
780825 """
781826 Data transformation to python datetime object.
@@ -868,6 +913,13 @@ def __init__(self, format=None, input_format=None, *args, **kwargs):
868913 self .input_format = input_format
869914 super ().__init__ (* args , ** kwargs )
870915
916+ def __deepcopy__ (self , memo = {}):
917+ return self .__class__ (
918+ required = self .required , default = self .default , label = self .label ,
919+ validators = self ._src_validators , error_messages = self ._src_messages ,
920+ format = getattr (self , 'format' , None ), input_format = getattr (self , 'input_format' )
921+ )
922+
871923 def to_internal_value (self , data ):
872924 """
873925 Data transformation to python datetime object.
@@ -958,6 +1010,13 @@ def __init__(self, format=None, input_format=None, *args, **kwargs):
9581010
9591011 super (DateTimeField , self ).__init__ (* args , ** kwargs )
9601012
1013+ def __deepcopy__ (self , memo = {}):
1014+ return self .__class__ (
1015+ required = self .required , default = self .default , label = self .label ,
1016+ validators = self ._src_validators , error_messages = self ._src_messages ,
1017+ format = getattr (self , 'format' ), input_format = getattr (self , 'input_format' )
1018+ )
1019+
9611020 def to_internal_value (self , data ):
9621021 """
9631022 Data transformation to python datetime object.
@@ -1083,6 +1142,13 @@ def __init__(self, child=None, *args, **kwargs):
10831142
10841143 self .child .bind (field_name = '' , parent = self ) # Bind child field.
10851144
1145+ def __deepcopy__ (self , memo = {}):
1146+ return self .__class__ (
1147+ required = self .required , default = self .default , label = self .label ,
1148+ validators = self ._src_validators , error_messages = self ._src_messages ,
1149+ child = self .child
1150+ )
1151+
10861152 def to_internal_value (self , data ):
10871153 """
10881154 Data transformation to python JSON object.
@@ -1161,6 +1227,13 @@ def __init__(self, method_name_get=None, method_name_pop=None, *args, **kwargs)
11611227 self .method_name_get = method_name_get
11621228 self .method_name_pop = method_name_pop
11631229
1230+ def __deepcopy__ (self , memo = {}):
1231+ return self .__class__ (
1232+ required = self .required , default = self .default , label = self .label ,
1233+ validators = self ._src_validators , error_messages = self ._src_messages ,
1234+ method_name_get = self .method_name_get , method_name_pop = self .method_name_pop
1235+ )
1236+
11641237 def bind (self , field_name , parent ):
11651238 """
11661239 Initialization field name and parent instance .
0 commit comments