def __setstate__(self, state):
    for key in state:
        value = state[key]
        {%- for field in fields %}
        {%if not loop.first%}el{%endif%}if key == '{{field}}':
            self._{{field}}_ = value
        {%- endfor %}        

def __getstate__(self):
    return {
        {%- for field in fields %}
        "{{field}}": self._{{field}}_,
        {%- endfor %}
    }