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

More like this

  1. Convert an instance to a dictionary for use in newforms by SmileyChris 6 years, 1 month ago
  2. Serializing booleans correctly when doing dumpdata from a MySQL database using Django 0.96 by chrj 4 years, 10 months ago
  3. Modify fields created by form_for_model by grahamu 6 years, 2 months ago
  4. Add validation for 'unique' and 'unique_together' constraints to newforms created dynamically via form_for_model or form_for_instance by bikeshedder 5 years, 11 months ago
  5. {% with %} template tag by SmileyChris 6 years, 2 months ago

Comments

(Forgotten your password?)