The first argument to instance methods is a handle to the current object, and should be called self
. This is standard python oo programming.
Also, loading dept inside the addEmployee
method makes no sense - it is hard coded to load "Finance" - what if you wanted to add an employee to the Sales dept?
I think your Department
class should look something more like this:
class Department(ndb.Model):
dept_name = ndb.StringProperty(required=True)
employees = ndb.KeyProperty(kind=Employee, repeated=True)
def addEmployee(self, employee):
self.employees.append(employee.key)
self.put()
Note I have also added kind=Employee
to the employees KeyProperty
, which will validate that you only add Keys of type Employee
to the list.