newforms field callback helper

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
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

Comments

(Forgotten your password?)

You may use Markdown syntax here, but raw HTML will be removed.