Ticket #899: django-use-model-default-as-newforms-initial.diff

File django-use-model-default-as-newforms-initial.diff, 1.1 KB (added by David Danier <goliath.mailinglist@…>, 18 years ago)

This should do it for current trunk (formfield() nicely refactored using super())

  • django/db/models/fields/__init__.py

    ==== Patch <django-use-model-default-as-newforms-initial> level 1
    Source: f4626db1-382e-0410-8594-a82d82b39f71:/use-model-default-as-newforms-initial/trunk:5026 [local]
    Target: bcc190cf-cafb-0310-a4f2-bffc1f526a37:/django/trunk:5133 [mirrored]
            (http://code.djangoproject.com/svn/django)
    Log:
     r4878@damasonium:  ddanier | 2007-04-16 14:28:02 +0200
      * Make model-field-default the initial value for newforms-fields
    
    === django/db/models/fields/__init__.py
    ==================================================================
     
    346346        defaults = {'required': not self.blank, 'label': capfirst(self.verbose_name), 'help_text': self.help_text}
    347347        if self.choices:
    348348            defaults['widget'] = forms.Select(choices=self.get_choices())
     349        if self.has_default():
     350            defaults['initial'] = self.get_default()
    349351        defaults.update(kwargs)
    350352        return form_class(**defaults)
    351353
Back to Top