user1607016
user1607016

Reputation: 475

TypeError: __init__() missing 1 required positional argument: 'model'

Beginner question. I have this class that basically relates a post to the user:

class Post(Model):
    timestamp = DateTimeField(default=datetime.datetime.now)
    user = ForeignKeyField(
        rel_model=User,
        related_name='posts'
        )
    content = TextField()

class Meta:
    database = DATABASE
    order_by = ('-timestamp',)

I get this error when it hits the 'related_name='posts' line:

Traceback (most recent call last):
File "app.py", line 5, in <module>
import forms
File "/dev/forms.py", line 2, in <module>
from models import User
File "/dev/models.py", line 41, in <module>
class Post(Model):
File "/dev/models.py", line 45, in Post
related_name='posts'
TypeError: __init__() missing 1 required positional argument: 'model'

The database I'm using is Sqlite (with Peewee). I don't understand why it's asking for a positional argument 'model', when Model is a parent class. What am I missing?

Upvotes: 1

Views: 2434

Answers (2)

coleifer
coleifer

Reputation: 26245

If you're using Peewee 3.x, then:

class Post(Model):
    timestamp = DateTimeField(default=datetime.datetime.now)
    user = ForeignKeyField(
        model=User,
        backref='posts')
    content = TextField()

    class Meta:
        database = DATABASE

Note: Meta.order_by is not supported in Peewee 3.x.

Upvotes: 2

saiKrishna kingdom
saiKrishna kingdom

Reputation: 77

model=model.DO_NOTHING

try this hope this work

Upvotes: 1

Related Questions