我是Flask和Peewee的新手,正在尝试使用Peewee的模型,我正在尝试允许用户创建新的约会,这些约会被添加到约会“数组”或某种类型,这样当我运行user.appointments
时,我就能够获得可用约会的数组。你知道吗
希望这是有意义的,如果不让我知道,我可以重新解释。你知道吗
我的代码在下面
class User(UserMixin, Model):
title = CharField(
choices=[
(1, 2, 3, 4),
('Mr', 'Mrs.', 'Ms.', 'Dr.',)
])
first_name = CharField()
sur_name = CharField()
email = CharField(unique=True)
password = CharField(max_length=100)
joined_at = DateTimeField(default=datetime.datetime.now)
profile_picture = ForeignKeyField(
rel_model=File,
related_name='profile_picture',
null=True
)
is_admin = BooleanField(default=False)
is_doctor = BooleanField(default=False)
class Meta:
database = db
order_by = ('-joined_at',)
@classmethod
def create_user(cls, title, first_name, sur_name, email,
password, doctor=False, admin=False):
if title is 4:
is_doctor = True
try:
cls.create(
title=title,
first_name=first_name,
sur_name=sur_name,
email=email,
password=generate_password_hash(password),
is_admin=admin,
is_doctor=doctor
)
except IntegrityError:
raise ValueError('Error creating user')
class Appointment(Model):
scheduled = DateTimeField()
date_created = DateTimeField(default=datetime.datetime.now)
notes = TextField()
class Meta:
database = db
@classmethod
def create_appointment(cls, scheduled, notes):
try:
cls.create(
scheduled=scheduled,
notes=notes
)
except IntegrityError:
raise ValueError('Error creating Appointment')
目前没有回答
相关问题 更多 >
编程相关推荐