>
> Actually, the API for creating a custom field type is 
> http://web2py.com/books/default/chapter/29/06/the-database-abstraction-layer#Custom-Field-types--experimental-.
>  
> Note, it isn't documented, but SQLCustomType also takes "validator", 
> "represent", "widget", and "_class" arguments, so you can specify defaults 
> for all of those attributes as well (i.e., no need to bother with 
> DAL.validator_method or _default_validators).
>

Thats great news, thanks Anthony.

@Dave S

> I'm inclined to say that this is a misapplication of "Boolean".   
> Tri-level logic is not Boolean.  Boolean is True or False.
>

Actually a bool tristate doesnt break that principle. Thats why it is the 
same database storage type.To your sentence i might add that "a boolean is 
always True or False whenever they are set".
Any database that i know of works like that, any field type will only store 
its data if they are set, if not, it will store some sort of NULL 
representing that the value wasnt set.

Note: booltristate is a feature on VisualBasic since 2000 or so. You can 
enable this feature on VB checkboxes and HTML is able to express them as 
radio inputs.

I can take advantage of this on this use case:
A booltri field "with_kids" is used to generate a query from a bookings 
table where kids is a boolean with all values set to True or False.

A quick example:
criteria = ""
if with_kids is None:
   #dont add any criteria to the query
   pass
elif with_kids is True:
   criteria = "bookings.kids = 1"
elif with_kids is False:
   criteria = "bookings.kids = 0"

If submit == "Save Filter":
  save with_kids to the db as a booltri, allowing NULL values on this field.

With an enumeration it could certainly be done but you need more db storage 
and you cannot map directly {0, 1, 2} to {NULL, 0, 1}. 

King Regards to you all.
This post was very helpful.
 

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to