I’m writing a db.Model class in google app engine that looks something like this:
class Cheese(db.Model):
name = db.StringProperty()
def say_cheese(self):
return name + "cheese"
For some reason, whenever I run:
cheese = Cheese(name = "smelly")
print thing.say_cheese()
I get a KindError – No implementation for kind ‘Cheese’. I want it to say: “smelly cheese”
Am I doing something wrong? Am I not allowed to add a method to a db.Model object?
It sounds like
thingis actually being loaded from adb.ReferenceProperty()field (on a non-Cheeseentity) which happens to be referring to aCheeseentity. If you access such a property without first importing theCheesemodel then the code won’t be able to find theCheesekind to construct the entity and will fail with the error you indicated.Anyway, try importing the
Cheesemodel in the code which is causing the error. Then the code should be able to find the implementation forCheesewhen it needs it.To answer the other part of your question: Yes, you are certainly allowed to add your own methods to a
db.Modelsubclass.