Is there a way to set the default value of a boolean field? Running
this quick test suggests to me that there is not, or at least I can't
figure out how to do it. Here's the example model:
db.define_table('snacks',
db.Field('name','string',
requires=[IS_NOT_EMPTY(),IS_NOT_IN_DB(db,'snacks.name')]),
db.Field('is_delicious', 'boolean', default=False,
requires=IS_NOT_EMPTY()),
)
In the model code above, I've tried putting various things after the
"default=", but I don't see any changes in the values that get
assigned to the is_delicious field. The data that I'm working with is
defined in the controller, shown below with each line's comment
showing what the application assigned to the 'is_delicious' value for
that line:
def insert_snacks():
snacks=[
Storage({'name':'apple','is_delicious':'True'}), #True
Storage({'name':'butter','is_delicious':'False'}), #True
Storage({'name':'chocolate','is_delicious':True}), #True
Storage({'name':'donut','is_delicious':False}), #False
Storage({'name':'empty bowl'}), #False
Storage({'name':'fig newton','is_delicious':'T'}), #True
Storage({'name':'gnats','is_delicious':'F'}), #True
Storage({'name':'hostess twinkie','is_delicious':1}), #True
Storage({'name':'iguana','is_delicious':0}), #False
Storage({'name':'jerky','is_delicious':''}),
#Invalid due to IS_NOT_EMPTY requirement
]
for s in snacks:
form.accepts(s,formname=None)
When setting the default in the model to True (or similar text and
numbers), the value for "empty bowl" is wrong. And with either True or
False default, it looks like the values for "butter" and "gnats"
probably should be handled better - although the input for these was
sloppy, it could be parsed as False.
Please let me know if I'm doing something wrong.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"web2py Web Framework" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/web2py?hl=en
-~----------~----~----~----~------~----~------~--~---