def serializer(cls, datum): ''' Serialize model object array (Convert into a list ''' results = [] for data in datum: obj = { 'id': hashid(data.id), 'user_id': hashid(data.user_id), 'name': data.name, 'description': data.description, 'category': data.category, 'country': data.country, 'city': data.city, 'reviews_count': Review.query.filter_by(business_id=data.id).count(), 'created_at': data.created_at, } results.append(obj) return results
def serialize_obj(cls, data): ''' Convert model object to dictionary ''' return { 'id': hashid(data.id), 'user_id': hashid(data.user_id), 'name': data.name, 'description': data.description, 'category': data.category, 'country': data.country, 'city': data.city, 'reviews_count': Review.query.filter_by(business_id=data.id).count(), 'created_at': data.created_at, }
def serialize_one(self): ''' Serialize model object array (Convert into a list) ''' obj = { 'id': hashid(self.id), 'user': User.query.get(self.user_id).username.capitalize(), 'description': self.description, 'created_at': self.created_at, } return obj
def serializer(cls, datum): ''' Serialize model object array (Convert into a list) ''' results = [] for data in datum: obj = { 'id': hashid(data.id), 'user': User.query.get(data.user_id).username.capitalize(), 'description': data.description, 'created_at': data.created_at, } results.append(obj) return results
def hashid(self): ''' Generate hashid ''' return hashid(self.id)