handle json field empty value case

This commit is contained in:
doubaniux 2021-02-16 00:19:14 +01:00
parent 155cfb44e8
commit 954813d359

View file

@ -15,7 +15,7 @@ class KeyValueInput(forms.Widget):
def get_context(self, name, value, attrs):
context = super().get_context(name, value, attrs)
data = json.loads(context['widget']['value'])
context['widget']['value'] = [ {p[0]: p[1]} for p in data.items()]
context['widget']['value'] = [ {p[0]: p[1]} for p in data.items()] if data else []
return context
class Media: