Ticket #4967: newforms_models_defaults.diff

File newforms_models_defaults.diff, 1.3 KB (added by Thomas Güttler <hv@…>, 17 years ago)
  • newforms/models.py

     
    6060        return save_instance(self, instance, fields, fail_message, commit)
    6161    return save
    6262
    63 def form_for_model(model, form=BaseForm, fields=None, formfield_callback=lambda f: f.formfield()):
     63def form_for_model(model, form=BaseForm, fields=None, formfield_callback=lambda f, **kwargs: f.formfield(**kwargs)):
    6464    """
    6565    Returns a Form class for the given Django model class.
    6666
     
    7070    determining the formfield for a given database field. It's a callable that
    7171    takes a database Field instance and returns a form Field instance.
    7272    """
     73    from django.db import models
    7374    opts = model._meta
    7475    field_list = []
    7576    for f in opts.fields + opts.many_to_many:
     
    7778            continue
    7879        if fields and not f.name in fields:
    7980            continue
    80         formfield = formfield_callback(f)
     81        if f.default==models.fields.NOT_PROVIDED:
     82            value=None
     83        else:
     84            value=f.default
     85        formfield = formfield_callback(f, initial=value)
    8186        if formfield:
    8287            field_list.append((f.name, formfield))
    8388    base_fields = SortedDictFromList(field_list)
Back to Top