1

I have a model like this:

class Person(models.Model,Subject):
    name = ..

The class Subject is not supposed to be in the Database so, it doesn't extends from models.Model:

class Subject:
    def __init__(self,**kargs):
        _observers = []

my problem is that the constructor of Subject is never called, so i've tried adding this to the class Person:

def __init__(self):
    super(Person,self).__init__()

but now i have an error saying that init takes 1 arguments but 7 are given, and the only thing i'm doing is

>>> Person.objects.get(pk=1)

now i'm lost =S do you have any idea how the constructor of person should be?

BTW: i'm using django 1.1 and python 2.6

0

2 Answers 2

1

First of all, use new-style classes (ones that inherit from object). Second, read about how python's super behaves in multiple inheritance scenarios: http://fuhm.net/super-harmful/

There is also a nice talk covering it: http://europythonvideos.blip.tv/file/4000758/

0
0

You can use Django's post_init signal. It's invoked after the model is instantiated, and is passed the instance that was created.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.