class Key(BaseMixin, TimestampMixin, db.Model): id = db.Column(db.Integer, primary_key=True) name = db.Column(db.String(length=255), nullable=False, unique=True) # IPv4 addresses are a maximum of 15 chars description = db.Column(db.Text, nullable=False) type = db.Column(db.Enum(*TYPES.keys()), nullable=False) data = db.relationship('Datum', backref='key', lazy='dynamic') def __repr__(self): return "<Key(name=%s, type=%s)>" % (self.name, self.type)
def value(self, value): converter = TYPES.get(self.key.type) self._value = str(converter(value))
def value(self): converter = TYPES.get(self.key.type) return converter(self._value)