from flask_restplus import Resource, fields, Namespace, marshal_with_field from .. import model as m api = Namespace('prefix', description = 'Operations on prefixes') prefix = api.model('Prefix', { 'name' : fields.String(required=True), 'description' : fields.String, 'virtual' : fields.Boolean }) @api.route('/') class PrefixList(Resource): @api.marshal_list_with(prefix) def get(self): """List all available non-virtual prefixes.""" return list(m.Prefix.select().where(~m.Prefix.virtual).dicts().iterator()) @api.route('/all') class PrefixListAll(Resource): @api.marshal_list_with(prefix) def get(self): """List all available prefixes, including virtual.""" return list(m.Prefix.select().dicts().iterator())