def get_by_attr(coupon_code): dic = Coupon.collection().find_one({"coupon_code": coupon_code}) return Coupon.unserialize(dic) if dic is not None else None