Je ne parviens pas à initialiser les champs d'un objet descendant "peewee.Model" à l'aide de l'outil habituel init (). Comment puis-je initialiser autrement ?
import peewee
peewee_database = peewee.SqliteDatabase('example.db')
class Config():
def __init__(self, seats, cylinders):
self.seats = seats
self.cylinders = cylinders
class Car(peewee.Model):
magic_number = peewee.IntegerField()
color = peewee.TextField()
class Meta:
database = peewee_database
def __init__(self, config):
self.magic_number = config.seats / config.cylinders
self.color = None
peewee_database.connect()
peewee_database.create_tables([Car])
config = Config(7, 6)
car = Car(config)
car.color = "blue"
car.save()
produit cette erreur dans Python3 :
File "test.py", line 27, in <module>
car = Car(config)
File "test.py", line 20, in __init__
self.magic_number = config.seats / config.cylinders
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/peewee.py", line 3764, in __set__
instance.__data__[self.name] = value
TypeError: 'NoneType' object does not support item assignment
aide ! :)