Set view name regardless of model name (App Engine data store)

As a Python programmer, I like my code to be reused, I try to avoid name conflicts in my code (where two different models have the same name).

Currently, I'm just adding some meaningful text to the model class name, but it's terribly messy.

The ability to explicitly determine the type of model will solve my problem, but I can’t find out how to do this, does anyone know how?

+3
source share
1 answer

Just override kind()your class method :

class MyModel(db.Model):
  @classmethod
  def kind(cls):
    return 'prefix_%s' % super(MyModel, cls).kind()

You can define a custom base class that will do this for you:

class ModuleModel(db.Model):
  @classmethod
  def kind(cls):
    return '%s_%s' % (cls.__module__, super(ModuleModel, cls).kind())

, ModuleModel, , .

+10

All Articles