コード例 #1
0
ファイル: models.py プロジェクト: josue-acosta/daycare
class Child(db.Document):
    first_name = db.StringField(maxlength=255, required=True)
    last_name = db.StringField(maxlength=255, required=True)
    birthday = db.DateTimeField()
    age_group = db.IntField()
    parent = db.ReferenceField(Parent)

    def calculate_age_group(self, birthday):
        today = date.today()
        months = ((today.year - birthday.year) * 12) + birthday.month
        age_group = None

        if months >= 36:
            age_group = 4
        elif months >= 12 and months < 36:
            age_group = 3
        elif months >= 6 and months < 12:
            age_group = 2
        elif months > 0 and months < 6:
            age_group = 1
        else:
            return "Could not calculate age group"

        return age_group

    def __repr__(self):
        return "<Children %r>" % self.id
コード例 #2
0
class Product(db.Document):
    created_at = db.DateTimeField(default=datetime.datetime.now, required=True)
    key = db.StringField(max_length=255, required=True)
    name = db.StringField(max_length=255, required=True)
    price = db.DecimalField()

    def __repr__(self):
        return '<Product %r>' % self.id
コード例 #3
0
ファイル: models.py プロジェクト: josue-acosta/daycare
class Parent(db.Document):
	first_name = db.StringField(maxlength=255, required=True)
	last_name = db.StringField(maxlength=255, required=True)
	phone = db.StringField(maxlength=255)
	address = db.StringField(maxlength=255)

	def __repr__(self):
		return "<Parent %r>" % self._id
コード例 #4
0
class User(db.Document):
    username = db.StringField(maxlength=255, required=True)
    password_hash = db.StringField(maxlength=255, required=True)

    def __init__(self, password=None, **data):
        if password is not None:
            data["password_hash"] = generate_password_hash(password)
        super(User, self).__init__(**data)

    def check_password(self, password):
        return check_password_hash(self.password_hash, password)

    def is_authenticated(self):
        return True

    def is_active(self):
        return True

    def is_anonymous(self):
        return False

    def get_id(self):
        return str(self.id)