1

In my django app's models.py, I inherit from two classes: models.Model and a class called Isbn10 from an imported Python module pyisbn. However, if I try to create an instance of the class, I get a TypeError: __init__() takes exactly 2 arguments (1 given)

I've tried reversing the parent class order, but it didn't help.

Model:

from django.db import models
import pyisbn

class Book10(pyisbn.Isbn10, models.Model):
    pass

Isbn Class definition (defined in pyisbn module):

class Isbn(object):
     def __init__(self, isbn):
        super(Isbn, self).__init__()
        self._isbn = isbn
        if len(isbn) in (9, 12):
            self.isbn = _isbn_cleanse(isbn, False)
        else:
            self.isbn = _isbn_cleanse(isbn)

1 Answer 1

2

Your init() definition requires both a self and a Isbn. So you'd have to pass both. Also, self should always be the first argument.

Sign up to request clarification or add additional context in comments.

1 Comment

Do you mean that I need Isbn(self, '9780887276309') to create a new instance? It doesn't work. Note that the Isbn class is defined in pyisbn which is a third-party python module not specific to django.

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.