We're doing a BFG app with a MongdoDB backend, and the Deform stuff seems
perfect for us, really enjoying using it so far.
But I can't figure out how to make a field in a schema optional if it's not a
String. (I've done this in Django model schemas where I can use the flag
null=True and blank=True on a non-string type). My reading of the docs says
that setting a field's
default=...
it makes a field non-required, and default='' is fine for String types, but not
so helpful for Integer, Date and other nonStrings. I've read doc mentioning
flags:
required=False
allow_empty=True
but allow_empty applies only to String and these seem to have no effect either.
I'm looking to do something like:
class StandardFields(colander.MappingSchema):
manufacturer= SchemaNode(String(), default='') # not
required
obsolete_date = SchemaNode(Date(),required=False,
allow_empty=True)
length = SchemaNode(Float(), required=False,
allow_empty=True)
units_per_pack = SchemaNode(Integer(), required=False,
allow_empty=True)
but find these don't work: my fields are required to be set. Supplying a
default value to indicate a non-required field, e.g.:
units_per_pack = SchemaNode(Integer(), default=0)
also feels wrong, since this will set the actual value to 0 upon storage to the
DB.
I am probably missing something in the docs. Perhaps I need a different
approach for non-required fields, like making the schema a String but having a
validator ensure they're my desired type if any value is provided on the form
-- this seems a round-about way to do things.
Any suggestions?
Thanks.
___
Repoze-dev mailing list
Repoze-dev@lists.repoze.org
http://lists.repoze.org/listinfo/repoze-dev