Open user706 opened 5 years ago
Hi, You can override to_struct method in your model, check if your value is None and do some stuff.
def to_struct(self):
self.validate()
resp = {}
for _, name, field in self.iterate_with_name():
value = field.__get__(self)
_type = type(field)
if value is None:
resp[name] = None
else:
value = field.to_struct(value)
resp[name] = value
return resp
Hi,
thanks for this nice lib.
Question 1: Am I correct in assuming that to create a field for any type, I'll have to subclass
fields.BaseField
? SeeAnyField
below.Question 2: Please see line marked with
# XXX
above. Is there any wayto get that printed as
{"whatever" : null}
? What would I need to change? (Are there any settings I missed?)Basically I want it to print the same as this...
Or do you reserve None as a special marker? (If so, could that marker be changed
to
class NoneMarker: pass
. But what would that mean for compatibility and upgrades, for other people...?)Thanks. Regards, user706