1

Here's a simplification of what I'm trying to accomplish:

class B inherits from A.

Class B is supposed to override the call_me method in class A.

I'm using google app engine (maybe that's why?)

from google.appengine.ext import ndb
from google.appengine.ext.ndb import polymodel

class A(polymodel.PolyModel):
    def call_me(self):
        print "super class called"
        return
    @classmethod
    def get_call_me(cls, qry)
        return [m.call_me() for m in qry]

class B(A):
    def call_me(self):
        print "sub class method called"
        return

When I call

object_b = B()
all_A = A.query() # get's object_b as well because object_b is an A
A.get_call_me(all_A)

I get "super class called" in the terminal.

How do I make sure "sub class method called" is fired instead/also?

class B is an A by inheritance (in the datastore it shows up as ['A', 'B']). But, I don't want call_me from class A to be called.

when I call B().__class__.__name__ , I get 'A'

What's the right way to go about this?

Never mind. It looks like this code works. I was using a projection qry so it didn't have access to the method? I don't quite understand how that works.

VictorGGl
  • 1,848
  • 10
  • 15

1 Answers1

1

Never mind. It looks like this code works. I was using a projection qry so I'm assuming I didn't have access to the method? I don't quite understand how that works. I'll figure it out later.

  • What do you mean by that you were using projection queries and that's why you were getting that behaviour? Can you edit you original post and add how you were using the projection queries? – VictorGGl Feb 23 '18 at 12:32
  • @VictorGGl see https://cloud.google.com/appengine/docs/standard/python/datastore/projectionqueries –  Mar 06 '18 at 17:12