Ticket #899: initial_formfield.patch
File initial_formfield.patch, 6.3 KB (added by , 18 years ago) |
---|
-
home/antisvin/svn/django/django/db/models/fields/__init__.py
343 343 344 344 def formfield(self, **kwargs): 345 345 "Returns a django.newforms.Field instance for this database Field." 346 defaults = {'required': not self.blank, 'label': capfirst(self.verbose_name), 'help_text': self.help_text }346 defaults = {'required': not self.blank, 'label': capfirst(self.verbose_name), 'help_text': self.help_text, 'initial': self.get_default()} 347 347 defaults.update(kwargs) 348 348 return forms.CharField(**defaults) 349 349 … … 405 405 return [oldforms.CheckboxField] 406 406 407 407 def formfield(self, **kwargs): 408 defaults = {'required': not self.blank, 'label': capfirst(self.verbose_name), 'help_text': self.help_text }408 defaults = {'required': not self.blank, 'label': capfirst(self.verbose_name), 'help_text': self.help_text, 'initial': self.get_default()} 409 409 defaults.update(kwargs) 410 410 return forms.BooleanField(**defaults) 411 411 … … 424 424 return str(value) 425 425 426 426 def formfield(self, **kwargs): 427 defaults = {'max_length': self.maxlength, 'required': not self.blank, 'label': capfirst(self.verbose_name), 'help_text': self.help_text }427 defaults = {'max_length': self.maxlength, 'required': not self.blank, 'label': capfirst(self.verbose_name), 'help_text': self.help_text, 'initial': self.get_default()} 428 428 defaults.update(kwargs) 429 429 return forms.CharField(**defaults) 430 430 … … 502 502 return {self.attname: (val is not None and val.strftime("%Y-%m-%d") or '')} 503 503 504 504 def formfield(self, **kwargs): 505 defaults = {'required': not self.blank, 'label': capfirst(self.verbose_name), 'help_text': self.help_text }505 defaults = {'required': not self.blank, 'label': capfirst(self.verbose_name), 'help_text': self.help_text, 'initial': self.get_default()} 506 506 defaults.update(kwargs) 507 507 return forms.DateField(**defaults) 508 508 … … 567 567 time_field: (val is not None and val.strftime("%H:%M:%S") or '')} 568 568 569 569 def formfield(self, **kwargs): 570 defaults = {'required': not self.blank, 'label': capfirst(self.verbose_name), 'help_text': self.help_text }570 defaults = {'required': not self.blank, 'label': capfirst(self.verbose_name), 'help_text': self.help_text, 'initial': self.get_default()} 571 571 defaults.update(kwargs) 572 572 return forms.DateTimeField(**defaults) 573 573 … … 586 586 validators.isValidEmail(field_data, all_data) 587 587 588 588 def formfield(self, **kwargs): 589 defaults = {'required': not self.blank, 'label': capfirst(self.verbose_name), 'help_text': self.help_text }589 defaults = {'required': not self.blank, 'label': capfirst(self.verbose_name), 'help_text': self.help_text, 'initial': self.get_default()} 590 590 defaults.update(kwargs) 591 591 return forms.EmailField(**defaults) 592 592 … … 723 723 return [oldforms.IntegerField] 724 724 725 725 def formfield(self, **kwargs): 726 defaults = {'required': not self.blank, 'label': capfirst(self.verbose_name), 'help_text': self.help_text }726 defaults = {'required': not self.blank, 'label': capfirst(self.verbose_name), 'help_text': self.help_text, 'initial': self.get_default()} 727 727 defaults.update(kwargs) 728 728 return forms.IntegerField(**defaults) 729 729 … … 762 762 763 763 def formfield(self, **kwargs): 764 764 from django.contrib.localflavor.usa.forms import USPhoneNumberField 765 defaults = {'required': not self.blank, 'label': capfirst(self.verbose_name), 'help_text': self.help_text }765 defaults = {'required': not self.blank, 'label': capfirst(self.verbose_name), 'help_text': self.help_text, 'initial': self.get_default()} 766 766 defaults.update(kwargs) 767 767 return USPhoneNumberField(**defaults) 768 768 … … 795 795 return [oldforms.LargeTextField] 796 796 797 797 def formfield(self, **kwargs): 798 defaults = {'required': not self.blank, 'widget': forms.Textarea, 'label': capfirst(self.verbose_name), 'help_text': self.help_text }798 defaults = {'required': not self.blank, 'widget': forms.Textarea, 'label': capfirst(self.verbose_name), 'help_text': self.help_text, 'initial': self.get_default()} 799 799 defaults.update(kwargs) 800 800 return forms.CharField(**defaults) 801 801 … … 840 840 return {self.attname: (val is not None and val.strftime("%H:%M:%S") or '')} 841 841 842 842 def formfield(self, **kwargs): 843 defaults = {'required': not self.blank, 'label': capfirst(self.verbose_name), 'help_text': self.help_text }843 defaults = {'required': not self.blank, 'label': capfirst(self.verbose_name), 'help_text': self.help_text, 'initial': self.get_default()} 844 844 defaults.update(kwargs) 845 845 return forms.TimeField(**defaults) 846 846 -
home/antisvin/svn/django/django/db/models/fields/related.py
553 553 setattr(cls, related.get_accessor_name(), ForeignRelatedObjectsDescriptor(related)) 554 554 555 555 def formfield(self, **kwargs): 556 defaults = {'queryset': self.rel.to._default_manager.all(), 'required': not self.blank, 'label': capfirst(self.verbose_name), 'help_text': self.help_text }556 defaults = {'queryset': self.rel.to._default_manager.all(), 'required': not self.blank, 'label': capfirst(self.verbose_name), 'help_text': self.help_text, 'initial': self.get_default()} 557 557 defaults.update(kwargs) 558 558 return forms.ModelChoiceField(**defaults) 559 559 … … 619 619 cls._meta.one_to_one_field = self 620 620 621 621 def formfield(self, **kwargs): 622 defaults = {'queryset': self.rel.to._default_manager.all(), 'required': not self.blank, 'label': capfirst(self.verbose_name), 'help_text': self.help_text }622 defaults = {'queryset': self.rel.to._default_manager.all(), 'required': not self.blank, 'label': capfirst(self.verbose_name), 'help_text': self.help_text, 'initial': self.get_default()} 623 623 defaults.update(kwargs) 624 624 return forms.ModelChoiceField(**defaults) 625 625