I have db.Model which has several properties as described below:
class Doc(db.Model):
docTitle = db.StringProperty(required=True)
docText = db.TextProperty()
docUser = db.UserProperty(required=True)
docDate = db.DateTimeProperty(auto_now_add=True)
In the template I just list the names of these documents as links. For that purpose I use the following query:
docList = Doc.gql("WHERE docUser = :1 ORDER BY docDate DESC", user)
As you can see docList includes all properties (including the "TextProperty"). However, I just use its docTitle and key() in my view.
Is there an alternative way to retrieve just the requested attributes of the model class?
If not, should I use PolyModel classes to differentiate the listing and actual usage of the Doc model class by creating another model class for the docText property?
EDIT: I am using webapp web framework in 开发者_开发百科google app engine...
Entities are stored in the App Engine datastore as serialized protocol buffers, which are returned as a single blob, so it's not possible to just retrieve part of them. In any case, this would only save on RPC overhead between the datastore and your app, so the savings would be minimal.
If the size of each entity is significant, you may want to separate the model out, as you suggest. You don't need to (and probably shouldn't) use PolyModel, though - just use two model classes, a 'summary' and a 'detail' one.
精彩评论