> If the datastore doesn't know about subclasses, I'm not sure they're > worth using.
I find that they help me with my code, but YMMV. (In particular, I often define db.ReferenceProperty s that only accept a base class and always fill them in with in instance of some subclass. That's better for me than untyped db.ReferenceProperty s or not using specialized subclasses.) > Couldn't I give Question all the properties I might > need, but only provide values to the ones each instance uses? Yes > Is > there any sort of penalty for declaring properties in a model, but not > using them? I don't think so. See http://code.google.com/appengine/docs/datastore/entitiesandmodels.html "Unlike relational databases, the App Engine datastore does not require that all entities of a given kind have the same properties. The application can specify and enforce its data models using the model API." If you want to get theoretical, google "universal relation". (Then you'd only have one entity class and almost all of the fields would be optional, filled it as appropriate on an instance-specific basis.) > add some sort notation of which subclass it is in the key_name and That's what I'd do, but then I have 10s of db.Model subclasses so the iterative query approach simply won't work for me. (However, I'm typically working with actual db.Key s so I don't run into this problem.) On Dec 10, 12:38 pm, theillustratedlife <[EMAIL PROTECTED]> wrote: > Thanks Andy. It's nice to know all the hidden features. =) > > If the datastore doesn't know about subclasses, I'm not sure they're > worth using. Couldn't I give Question all the properties I might > need, but only provide values to the ones each instance uses? Is > there any sort of penalty for declaring properties in a model, but not > using them? > > It looks like my other options is to build a helper function that gets > a Question instance from a key_name, like one of thses: > > instance = None > subclasses = [ShortAnswerQuestion, MultipleChoiceQuestion, ] > while instance is None: > instance = subclasses.pop().get_by_key_name(key_name) > > or add some sort notation of which subclass it is in the key_name and > > instance = None > subclass = None > > if key_name_fragment == 'sa': > subclass = ShortAnswerQuestion > elif key_name_fragment == 'mc': > subclass = MultipleChoiceQuestion > > instance = subclass.get_by_key_name(key_name) > > So now I need to decide if it's even worth using subclasses, and if > so, how to go about turning a key_name into an instance. Advice? --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Google App Engine" 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/google-appengine?hl=en -~----------~----~----~----~------~----~------~--~---
