Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8874021
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T18:36:59+00:00 2026-06-14T18:36:59+00:00

With an instance of Concert I get: unbound method do_stuff() must be called with

  • 0

With an instance of Concert I get: unbound method do_stuff() must be called with Concert instance as first argument (got ModelBase instance instead)

models.py:

class Event(models.Model):
    def do_stuff(self):
        response self.do_specific_stuff(self)


class Concert(Event):
    def do_specific_stuff(self):
        ...

class Party(Event):
    def do_specific_stuff(self):
        ...

views:

def index(request):
    x = Concert.objects.get(name='Jack White @ Oakland')
    output = x.do_stuff()
    return HttpResponse(output)

My goal is to loop trough all the events and execute the do_specific_stuff child class method based on what kind of event it is.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T18:37:05+00:00Added an answer on June 14, 2026 at 6:37 pm

    In Django, inheritance triggers multi-table inheritance, but you don’t get the polymorphism in Python. It’s just an instance of the ORM not providing a perfect correspondence between the data schema and the object model.

    In other words, when you query Event, you get back a whole bunch of Event objects, regardless of whether some of them are actually Concert or Party objects. You have to manually downcast. If an Event is a Concert, it will have an attribute called concert, which points to the corresponding Concert subclass. Likewise for Party. If it is just a normal Event, it will have neither attribute.

    You could use the following property on Event to automatically downcast your object:

    @property
    def as_child_class(self):
        """Casts this object to its subclass, if possible"""
    
        if hasattr(self, 'concert'):
            return self.concert
        elif hasattr(self, 'party'):
            return self.party
        else:
            return self
    

    Then you could do something like:

    for event in Event.objects.all()
        event.as_child_class.do_specific_stuff()
    

    Similar questions have come up before:

    • Polymorphism in Django
    • How do I access the child classes of an object in django without knowing the name of the child class?

    And this link has some other ideas:

    • http://jeffelmore.org/2010/11/11/automatic-downcasting-of-inherited-models-in-django/
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: how to get class instance of generics type T Template's T at
For instance, if I have an class: public class StuffHolder { List<Stuff> myList; public
Consider the following sample code: class SampleClass { public long SomeProperty { get; set;
I'm trying to get a better idea of how my SQL 2000 instance is
I am trying to instantiate an instance of the ListEx class in my StoreNames()
How do I get a random decimal.Decimal instance? It appears that the random module
I'm getting Me' is valid only within an instance method error when I convert
I've got a solution consisting of several projects (all class libraries). Let's say: A,
I'm trying to use a method from a Java class whose parameter type is
Is there any way to convert a android.graphics.Bitmap instance into jpeg in android?

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.