I can't find out how to init a Model class ...
# Define mongoengine documents
class User(db.Document, UserMixin):
name = db.StringField(max_length=75,primary_key=True)
email = db.EmailField(max_length=255,unique=True,required=True)
password = db.StringField()
created_on = db.DateTimeField(
default=datetime.datetime.now, required=True
)
isActive = db.BooleanField(default=True)
isAuthenticated = db.BooleanField(default=False)
isAdmin = db.BooleanField(default=False, required=False)
meta = {'collection': 'users'}
def __init__(self,name,email,password,created_on,isActive=True,isAuthenticated=False,isAdmin=False):
self.name=name
self.email=email
self.password = bcrypt.generate_password_hash(
password, app.config.get('BCRYPT_LOG_ROUNDS')
).decode('utf-8')
self.created_on==datetime.datetime.now()
self.isActive = isActive
self.isAuthenticated = isAuthenticated
self.isAdmin = isAdmin
I get the following error:
TypeError: __init__() missing 4 required positional arguments: 'name', 'email', 'password', and 'created_on'
I'm not sure what I'm missing, the syntax seems correct.
The model works (with unsalted password) when I remove the init function
Is this a Python3 vs Python2 kind of issue?
Full traceback: [https://gist.github.com/642ad5c9d86a3bb8da70757636424209]