Inheriting assigned properties from a mix-in
I would like to use a mix-in class to add properties to a model.
from google.appengine.ext import db
class Taggable(object):
tag_list = db.StringListPro开发者_JS百科perty()
def attach_tag(self, tag):
self.tag_list.append(tag)
self.put()
def remove_tag(self, tag):
self.tag_list.pop(self.tag_list.index(tag))
self.put()
class Post(db.Model, Taggable):
title = db.TextProperty()
This is just an example, no need to chew my ear off about bad practices or something.
Currently, I have something similar to this, except I have to put tag_list = db.StringListProperty()
outside of the mix-in (errors otherwise), this is messy code, and I would like to avoid that.
Simply, how can I assign properties (such as tag_list
) to a model from within a mix-in?
Should not Taggable be based on db.Model instead of object?
精彩评论