def new_callback(exclude=None, include=None): """ Create a form callback which excludes or only includes certain fields. """ def _callback(field, **kwargs): if include and field.name not in include: return None if exclude and field.name in exclude: return None return field.formfield(**kwargs) return _callback