Class documentation¶
DateListField¶
-
class
DateListField(fields.CharField)¶ The class
DateListFieldprovides a django form field for storing dates, it actually is a sublcass of (django.forms.fields.CharField).You can use the same arguments as for a
django.forms.fields.CharField, for examplemax_lengthormin_length. Note that this is the length of the text field that is used to store a JSON list representation of the selected dates, NOT the number of dates. The JSON representation is given in the format"yyyy/mm/dd", the JSON string may also contain"[","]",","etc. So you should setmax_lengthto something reasonable by yourself.You can also use
required=Trueas for a “normal”CharField, this means that at least one date must be selected.-
to_python(value)¶ Translates the string representation (value) to a list of dates
Parameters: value (str) – The string to translate Raises: ValidationError – If value isn’t a valid JSON string Note
Usually you don’t have to call this method yourself - django will take care of it if you use this field in a form.
This method will call the
to_pythonmethod ofCharFieldin order to perform the validation checks there (like length validation). It further tries to parse the input as JSON. If the input isn’t valid JSON it raises aValidationError. The JSON must contain a list of strings in the right format, i.e."yyyy/mm/dd"with valid values for year, month and day (as described indatetime.date). If this isn’t the case, the method raises aValidationError.Note
The months in javascript are zero based, so January is represented by
"00". This method always adds one to the month because the python constructor uses values 1 <= month <= 12.
-