0

I get an error with model like this:

class Project(models.Model):  # Should Rename to Project Name
    project_name = models.CharField(max_length=50)
    frequency = models.PositiveIntegerField(blank=True)
    related_tests = models.ManyToManyField(TestType)
    creation_date = models.DateField()

    def __init__(self, *args, **kwargs):
        super().__init__(self, *args, **kwargs)
        self.creation_date = datetime.date.today()

Error: int() argument must be a string, a bytes-like object or a number, not 'Project'

When I comment out,

    creation_date = models.DateField()

    def __init__(self, *args, **kwargs):
        super().__init__(self, *args, **kwargs)
        self.creation_date = datetime.date.today()

...the code works.

My question is, what is prompting the error?

4
  • 2
    Don't just post the final error message. Post the entire error traceback, so we can see what line of code caused the error. Commented Jun 6, 2016 at 16:27
  • 1
    When submitting a question like this, it's helpful to see a) the version of python being used, b) the version of django being used, c) all the code involved (I don't see how you get that error without actually trying to create a Project object). Commented Jun 6, 2016 at 16:29
  • See minimal reproducible example for advice on posting a problem. Commented Jun 6, 2016 at 16:34
  • Thanks guys. Regarding why I did not post the entire traceback, I knew problem was in that those lines of code and those alone so there was no reason to bother people with entire traceback. The answer below pointed me to the right direction. Commented Jun 6, 2016 at 18:16

1 Answer 1

3

You don't need to pass self to __init__ with super:

super().__init__(*args, **kwargs)

Or in python 2, you should do:

super(Project, self).__init__(*args, **kwargs)
Sign up to request clarification or add additional context in comments.

1 Comment

I missed that! Think you've found it.

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.