Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

235
Views
parent calling abstract method in python

I'm new to python. I want to define some abstract methods in my parent class and use them. I wrote a code like this

class BaseListAPI(APIView):
    __metaclass__  = abc.ABCMeta

    def get(self, request):
        search_object, start, count = 
        tools.handlers.read_get_request_data(request.GET)
        order_by = request.GET.get('order_by')

        return get_successful_response(self.get_query_set.list(
            without_user_serializer=self.get_serializer,
            search_object=search_object,
            start=start,
            count=count,
            order_by=order_by
        ))

    @abc.abstractmethod
    def get_query_set(self):
        """Method that should do something."""

    @abc.abstractmethod
    def get_serializer(self):
        """this method gets the serializer"""


class TourListListAPI(BaseListAPI):
    def get_query_set(self):
        return models.Tour.objects

    def get_serializer(self):
        return without_user.TourSerializer

When i call self.get_query_set() for example i expect the child function call but it never get called instead abstract parent methods getting called witch results in an error!! What i'm missing here?

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

I just made a silly mistake! It wasn't working because it didn't put parentheses when calling functions is parent class! now this work like a charm.

class BaseListAPI(APIView):
    __metaclass__  = abc.ABCMeta

    def get(self, request):
        search_object, start, count = 
        tools.handlers.read_get_request_data(request.GET)
        order_by = request.GET.get('order_by')

        return get_successful_response(self.get_query_set().list(
            without_user_serializer=self.get_serializer(),
            search_object=search_object,
            start=start,
            count=count,
            order_by=order_by
        ))

    @abc.abstractmethod
    def get_query_set(self):
        """Method that should do something."""

    @abc.abstractmethod
    def get_serializer(self):
        """this method gets the serializer"""
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!