22 lines
535 B
Python
22 lines
535 B
Python
|
from django.forms import widgets
|
||
|
|
||
|
|
||
|
class CommaSeparatedTextInput(widgets.HiddenInput):
|
||
|
def format_value(self, value):
|
||
|
try:
|
||
|
value = ','.join(value)
|
||
|
except TypeError:
|
||
|
value = ''
|
||
|
return super().format_value(value)
|
||
|
|
||
|
def value_from_datadict(self, data, files, name):
|
||
|
value = super().value_from_datadict(data, files, name)
|
||
|
|
||
|
if value == '':
|
||
|
return None
|
||
|
|
||
|
try:
|
||
|
return value.split(',')
|
||
|
except AttributeError:
|
||
|
return None
|