petr
petr

Reputation: 2586

Multiple inheritance mixing ndb.Model with PolyModel in AppEngine

In my application we are using a base model to hold general properties, which is a simple subclass of the ndb.Model. However, for some of the functionality it is very helpful to be able to leverage polymodel functionality. Both Model and PolyModel supposedly support multiple inheritance, my question is, are there any caveats of doing the below?

from google.appengine.ext import ndb
from google.appengine.ext.ndb import polymodel    

class InternalBase(ndb.Model):
   # some fields, methods shared to many sub-models

class Widget(polymodel.PolyModel, InternalBase):
   # widget-general

class TextWidget(Widget):
   # widget-specific

class HTMLWidget(Widget):
   # widget-specific

The goal is to have all the basic properties and methods from InternalBase available to the Widget class but also to be able to search for all subclasses of Widget using a single query (which is what the PolyModel adds).

Also, could you think of a test-case that could expose any potential problem with such scheme?

Upvotes: 3

Views: 892

Answers (0)

Related Questions