[Answered ]-How to populate a bespoke Django form MultiWidget

1👍

Since address is stored as models.TextField() and retrieved as Python str in the model:

  1. In MultiWidget decompress, load from str:
class AddressWidget(MultiWidget):
    ...

    def decompress(self, value):
        if value:
            return json.loads(value)
        return (None, None, None, None, None)
  1. In MultiValueField compress, dump to str:
class AddressField(MultiValueField):
    ...

    def compress(self, value_list):
        if value_list:
            return json.dumps(value_list)
        return ''
👤aaron

Leave a comment