Yes, I will try to post and example tonight. I believe your students will REALLY like this...
Here are a few DALnr snippets till then: In gql.py from google.appengine.ext import db as google_db from google.appengine.ext.db import polymodel as pm # DLypka Mod to support PolyModel : : class MyGAEBaseTreeLevel(pm.PolyModel): #DLypka Mod selflinkPrev = google_db.SelfReferenceProperty (collection_name='selflinksPrev') selflinkNext = google_db.SelfReferenceProperty (collection_name='selflinksNext') class MyGAEBaseTreeLevelSegment(pm.PolyModel): #DLypka Mod This entity is a child of MyGAEBaseTreeLevel linkToTreeLevel = google_db.ReferenceProperty(MyGAEBaseTreeLevel, required=False, collection_name='linksToTreeLevel') In Method def _select(self, *fields, **attributes): : : # tablename = table.kind() # DLypka commented out for PolyModel support tablename = table.class_name() # DLypka Patch for PolyModel support In Method def _create(self): : : if self._tablename == 'MyGAEBaseTreeLevel': self._tableobj = classobj(self._tablename, (MyGAEBaseTreeLevel, ), myfields) elif self._tablename == 'MyGAEBaseTreeLevelSegment': self._tableobj = classobj(self._tablename, (MyGAEBaseTreeLevelSegment, ), myfields) elif self._tablename == 'MyGAEBaseTreeItem': self._tableobj = classobj(self._tablename, (MyGAEBaseTreeItem, ), myfields) else: self._tableobj = classobj(self._tablename, (google_db.Model, ), myfields) return None ---------------------------------------------------------------------------------------- In db.py: # Create a Parent Entity: myTreeLevelNativeInstance00keys = db.TreeLevel.insertNative(level=0, name='TreeLevel_01') # I cloned insert() but I return a dict() with the native ref as well as id myTreeLevelNativeInstance00 = myTreeLevelNativeInstance00keys ['nativeRef'] myTreeLevelNativeInstance00id = myTreeLevelNativeInstance00keys['id'] rows=db(db.TreeLevel.id > 0).select() for row in rows: myTreeLevelInstance00 = row # NOTE: There is only a single row here, so myTreeLevelInstance00 will be the row we just inserted into the web2py DAL myTreeLevelSegmentNativeInstance00_00keys = db.TreeLevelSegment.insertNative(idTreeLevel = myTreeLevelNativeInstance00id, level=0, name='TreeLevelSegment_00_01') myTreeLevelSegmentNativeInstance00_00 = myTreeLevelSegmentNativeInstance00_00keys['nativeRef'] myTreeLevelSegmentNativeInstance00_00.linkToTreeLevel=myTreeLevelNativeInstance00 # <=== NOTE This is the Interesting part !!! ======= myTreeLevelSegmentNativeInstance00_00.put() # This rewrites (updates) the entity links1 = myTreeLevelNativeInstance00.linksToTreeLevel # <=== NOTE: This is EXTREMELY Interesting!! - this property was AUTOMATICALLY maintained by the automatic bidirectional nature of the ReferenceProperty, so that the 'parent' has a list of refs to its related children, without any explicit code to add them!!! # links1 is a google.appengine.ext.db.query # It is a db.Query # Here you should loop on links1 which is a column on the parent entity and see what you get for key in links1: childref = key # childref is (magically) a TreeLevelSegment which is a child of TreeLevel -- End of DALnr Snippets for GAE --- - Dave Lypka. On Aug 4, 12:27 am, mdipierro <mdipie...@cs.depaul.edu> wrote: > Can you show us an example? > > On Aug 3, 9:01 am, dlypka <dly...@gmail.com> wrote: > > > > > PolyModel enables true polymorphic behavior when querying objects > > whose classes are derived from other classes. > > So, in the retrieved instance, all fields of all classes at and above > > the target class are available to the retrieved instance. > > > When PolyModel is not used as the base class, then the query only > > returns the attributes of the queried class. > > Attributes of inherited classes are uninitialized. > > > So using PolyModel as the base class, the web2py DAL classes can carry > > along GAE-specific attributes in base classes, > > one of the most useful being the Reference attribute, which will link > > together related instances so that GAE will return them in a single > > query. > > Also, Reference gives automatic bidirectional links. > > > On Aug 2, 1:17 pm, mdipierro <mdipie...@cs.depaul.edu> wrote: > > > > What is PolyModel? How is different than what DAL already does when > > > running on GAE? > > > > On Aug 2, 11:33 am, dlypka <dly...@gmail.com> wrote: > > > > > I just got an experimental version of T3 to work with the PolyModel > > > > base class in GAE. > > > > That gives inherited Classes. > > > > So GAE is Quite Amazing. > > > > > I almost have my own DALnr ('nr' = non relational) for web2py working > > > > with GAE now. > > > > It is using my 'Phantom' Field concept (special table fields in a > > > > db.define_table(...) which do native GAE operations but are not > > > > otherwise part of the list of columns for that web2py table) > > > > > In particular I got PolyModel to work together with the Reference > > > > feature which links together the related entities so that GAE loads > > > > them ***ALL*** in a > > > > single datastore query. > > > > > In theory, my DALnr will allow creating web2py models which will work > > > > on both SQL and GAE and will automatically use 'nr' GAE native > > > > features if on GAE. > > > > > ToDo: I still have to generalize my DALnr code. > > > > > My first application of this DALnr is to a high performance TreeView > > > > control which loads all branches of a given level in PARALLEL using > > > > async multi simultaneous Ajax callbacks. > > > > > On Aug 2, 11:34 am, Pynthon <forumx...@gmail.com> wrote: > > > > > > IMO GAE is too difficult :P. > > > > > > On 2 aug, 07:02, Bottiger <bottig...@gmail.com> wrote: > > > > > > > Google has sunk too much time and effort into adapting Django to > > > > > > recommend another framework. They also need to attract more users to > > > > > > GAE which Django has plenty of. > > > > > > > On Aug 1, 3:12 pm, mdipierro <mdipie...@cs.depaul.edu> wrote: > > > > > > > > Yes, if only they'd understand we support GAE better than Django > > > > > > > does. > > > > > > > Our DAL and our appadmin work on GAE, the Django ORM and Django > > > > > > > admin > > > > > > > do not as far as I know. > > > > > > > > Massimo > > > > > > > > On Aug 1, 3:10 pm, Pynthon <forumx...@gmail.com> wrote: > > > > > > > > > Watch > > > > > > > > this:http://googleappengine.blogspot.com/2009/05/web2py-support-new-datast... --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "web2py-users" group. To post to this group, send email to web2py@googlegroups.com To unsubscribe from this group, send email to web2py+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/web2py?hl=en -~----------~----~----~----~------~----~------~--~---