Google App Engine: KindError - no implementation for the view "ObjectName"

I am writing a db.Model class in a Google 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 KindError - there is no implementation for the Cheese view. I want to say "stinky cheese"

Am I doing something wrong? Am I not allowed to add a method to a db.Model object?

+4
source share
1 answer

It seems that thing actually loading from the db.ReferenceProperty() field (on the Cheese object), which seems to be related to the Cheese object. If you gain access to such a property without first importing the Cheese model, then the code will not be able to find the Cheese type for creating the object and the error you specified will fail.

In any case, try importing the Cheese model into the code that causes the error. Then the code should be able to find an implementation for Cheese when necessary.

To answer another part of your question: Yes, of course you can add your own methods to a subclass of db.Model .

+10
source

Source: https://habr.com/ru/post/1315456/


All Articles