Here is a patch.

On Tuesday, January 7, 2014 9:03:48 AM UTC+1, Massimo Di Pierro wrote:
>
> Thank you. I will take care of this asap. Can you submit a patch?
>
> On Friday, 3 January 2014 04:10:11 UTC-6, Quint wrote:
>>
>> I created an issue for this:
>>
>> https://code.google.com/p/web2py/issues/detail?id=1842
>>
>> On Thursday, January 2, 2014 6:45:59 PM UTC+1, Quint wrote:
>>>
>>> Hello everybody,
>>>
>>> Happy New Year!
>>>
>>> I'm using GAE and sometimes a need to call some GAE datastore functions 
>>> directly.
>>>
>>> (For instance when I want to supply a "key_name" when I put() an entity 
>>> so I can have better performance to get() that entity from db.
>>> Or when I want to use put_multi())
>>>
>>> Anyway, I can use the "*_tableobj*" property of the web2py table to 
>>> access the GAE model class.
>>>
>>> But, this class does not have the defaults applied to it's properties 
>>> while the Fields on the web2py table do.
>>> This means that when I put() my _tableobj instance (using GAE API) , 
>>> the defaults are not set in the database record.
>>>
>>> At the moment a call this function in my db model after each table 
>>> definition:
>>>
>>>
>>> @classmethod
>>>     def set_defaults(cls, table):
>>>         """
>>>         Takes a web2py table and sets the defaults of all Fields and sets
>>>         those defaults on the associated properties of the tableobj
>>>         (tableobj = the GAE model class associated with the web2py table)
>>>         """
>>>         for propname, prop in table._tableobj._properties.iteritems():
>>>             field = getattr(table, propname, None)
>>>             if None != field and isinstance(field, Field):
>>>                 prop._default = field.default
>>>
>>> Can this (or something like this) be integrated in the create_table() 
>>> method of GoogleDatastoreAdapter() so it's done when the table gets created?
>>>
>>> Thanks,
>>>
>>> Regards
>>>
>>> Quint
>>>
>>>

-- 
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/groups/opt_out.
Index: E:/repositories/Mercurial/web2py/gluon/dal.py
===================================================================
--- E:/repositories/Mercurial/web2py/gluon/dal.py	(revision 5706:f691e2676f64)
+++ E:/repositories/Mercurial/web2py/gluon/dal.py	(revision 5706+:f691e2676f64+)
@@ -4941,6 +4941,16 @@
             table._tableobj = classobj(table._tablename, (polymodel._tableobj, ), myfields)
         else:
             raise SyntaxError("polymodel must be None, True, a table or a tablename")
+
+        # Set defaults on the GAE model class (tableobj)
+        for propname, prop in table._tableobj._properties.iteritems():
+            field = getattr(table, propname, None)
+            if None != field and isinstance(field, Field):
+                if self.use_ndb:
+                    prop._default = field.default
+                else:
+                    prop.default = field.default
+
         return None
 
     def expand(self,expression,field_type=None):

Reply via email to