Ticket #5238: initial-default.diff

File initial-default.diff, 965 bytes (added by Kevin Menard, 17 years ago)
  • django/newforms/models.py

     
    7777    determining the formfield for a given database field. It's a callable that
    7878    takes a database Field instance and returns a form Field instance.
    7979    """
     80    from django.db.models.fields import NOT_PROVIDED
     81   
    8082    opts = model._meta
    8183    field_list = []
    8284    for f in opts.fields + opts.many_to_many:
     
    8688            continue
    8789        formfield = formfield_callback(f)
    8890        if formfield:
     91            # Set the initial form field value based on the model field's default value.
     92            if f.default != NOT_PROVIDED:
     93                formfield.initial = f.default
    8994            field_list.append((f.name, formfield))
    9095    base_fields = SortedDictFromList(field_list)
    9196    return type(opts.object_name + 'Form', (form,),
Back to Top