0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

各フィールドのバリデーション設定 @validates / モデル 一対一

Last updated at Posted at 2025-05-02
@validates('name')
    def validate_name(self, key, value):
        if len(value) > 64:
            raise ValueError("名前は64文字以内で入力してください。")
        return value

    @validates('birthdate')
    def validate_birthdate(self, key, value):
        if value and value > date.today():
            raise ValueError("生年月日は未来の日付にできません。")
        return value

UserモデルとProfileモデル 関連付ける

class User(db.Model, UserMixin):
    profile = db.relationship('Profile', backref='user', uselist=False)

class Profile(db.Model):
    user_id = db.Column(db.Integer, db.ForeignKey('user.id'))
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?