Ticket #3292: models_widgets.patch
File models_widgets.patch, 8.5 KB (added by , 18 years ago) |
---|
-
django/db/models/fields/__init__.py
70 70 core=False, rel=None, default=NOT_PROVIDED, editable=True, 71 71 prepopulate_from=None, unique_for_date=None, unique_for_month=None, 72 72 unique_for_year=None, validator_list=None, choices=None, radio_admin=None, 73 help_text='', db_column=None ):73 help_text='', db_column=None, widget=None): 74 74 self.name = name 75 75 self.verbose_name = verbose_name 76 76 self.primary_key = primary_key … … 86 86 self.radio_admin = radio_admin 87 87 self.help_text = help_text 88 88 self.db_column = db_column 89 self.widget = widget 89 90 90 91 # Set db_index to True if the field has a relationship and doesn't explicitly set db_index. 91 92 self.db_index = db_index … … 337 338 def formfield(self, initial=None): 338 339 "Returns a django.newforms.Field instance for this database Field." 339 340 # TODO: This is just a temporary default during development. 340 return forms.CharField(required=not self.blank, label=capfirst(self.verbose_name), initial=initial )341 return forms.CharField(required=not self.blank, label=capfirst(self.verbose_name), initial=initial, widget=self.widget) 341 342 342 343 def value_from_object(self, obj): 343 344 "Returns the value of this field in the given model instance." … … 397 398 return [oldforms.CheckboxField] 398 399 399 400 def formfield(self, initial=None): 400 return forms.BooleanField(required=not self.blank, label=capfirst(self.verbose_name), initial=initial )401 return forms.BooleanField(required=not self.blank, label=capfirst(self.verbose_name), initial=initial, widget=self.widget) 401 402 402 403 class CharField(Field): 403 404 def get_manipulator_field_objs(self): … … 414 415 return str(value) 415 416 416 417 def formfield(self, initial=None): 417 return forms.CharField(max_length=self.maxlength, required=not self.blank, label=capfirst(self.verbose_name), initial=initial )418 return forms.CharField(max_length=self.maxlength, required=not self.blank, label=capfirst(self.verbose_name), initial=initial, widget=self.widget) 418 419 419 420 # TODO: Maybe move this into contrib, because it's specialized. 420 421 class CommaSeparatedIntegerField(CharField): … … 488 489 return {self.attname: (val is not None and val.strftime("%Y-%m-%d") or '')} 489 490 490 491 def formfield(self, initial=None): 491 return forms.DateField(required=not self.blank, label=capfirst(self.verbose_name), initial=initial )492 return forms.DateField(required=not self.blank, label=capfirst(self.verbose_name), initial=initial, widget=self.widget) 492 493 493 494 class DateTimeField(DateField): 494 495 def to_python(self, value): … … 549 550 time_field: (val is not None and val.strftime("%H:%M:%S") or '')} 550 551 551 552 def formfield(self, initial=None): 552 return forms.DateTimeField(required=not self.blank, label=capfirst(self.verbose_name), initial=initial )553 return forms.DateTimeField(required=not self.blank, label=capfirst(self.verbose_name), initial=initial, widget=self.widget) 553 554 554 555 class EmailField(CharField): 555 556 def __init__(self, *args, **kwargs): … … 566 567 validators.isValidEmail(field_data, all_data) 567 568 568 569 def formfield(self, initial=None): 569 return forms.EmailField(required=not self.blank, label=capfirst(self.verbose_name), initial=initial )570 return forms.EmailField(required=not self.blank, label=capfirst(self.verbose_name), initial=initial, widget=self.widget) 570 571 571 572 class FileField(Field): 572 573 def __init__(self, verbose_name=None, name=None, upload_to='', **kwargs): … … 701 702 return [oldforms.IntegerField] 702 703 703 704 def formfield(self, initial=None): 704 return forms.IntegerField(required=not self.blank, label=capfirst(self.verbose_name), initial=initial )705 return forms.IntegerField(required=not self.blank, label=capfirst(self.verbose_name), initial=initial, widget=self.widget) 705 706 706 707 class IPAddressField(Field): 707 708 def __init__(self, *args, **kwargs): … … 758 759 return [oldforms.LargeTextField] 759 760 760 761 def formfield(self, initial=None): 761 return forms.CharField(required=not self.blank, widget=forms.Textarea, label=capfirst(self.verbose_name), initial=initial)762 return forms.CharField(required=not self.blank, label=capfirst(self.verbose_name), initial=initial, widget=self.widget or forms.Textarea) 762 763 763 764 class TimeField(Field): 764 765 empty_strings_allowed = False … … 801 802 return {self.attname: (val is not None and val.strftime("%H:%M:%S") or '')} 802 803 803 804 def formfield(self, initial=None): 804 return forms.TimeField(required=not self.blank, label=capfirst(self.verbose_name), initial=initial )805 return forms.TimeField(required=not self.blank, label=capfirst(self.verbose_name), initial=initial, widget=self.widget) 805 806 806 807 class URLField(CharField): 807 808 def __init__(self, verbose_name=None, name=None, verify_exists=True, **kwargs): … … 818 819 return "CharField" 819 820 820 821 def formfield(self, initial=None): 821 return forms.URLField(required=not self.blank, verify_exists=self.verify_exists, label=capfirst(self.verbose_name), initial=initial )822 return forms.URLField(required=not self.blank, verify_exists=self.verify_exists, label=capfirst(self.verbose_name), initial=initial, widget=self.widget) 822 823 823 824 class USStateField(Field): 824 825 def get_manipulator_field_objs(self): -
django/db/models/fields/related.py
549 549 setattr(cls, related.get_accessor_name(), ForeignRelatedObjectsDescriptor(related)) 550 550 551 551 def formfield(self, initial=None): 552 return forms.ChoiceField(choices=self.get_choices_default(), required=not self.blank, label=capfirst(self.verbose_name), initial=initial )552 return forms.ChoiceField(choices=self.get_choices_default(), required=not self.blank, label=capfirst(self.verbose_name), initial=initial, widget=self.widget) 553 553 554 554 class OneToOneField(RelatedField, IntegerField): 555 555 def __init__(self, to, to_field=None, **kwargs): … … 613 613 cls._meta.one_to_one_field = self 614 614 615 615 def formfield(self, initial=None): 616 return forms.ChoiceField(choices=self.get_choices_default(), required=not self.blank, label=capfirst(self.verbose_name), initial=initial )616 return forms.ChoiceField(choices=self.get_choices_default(), required=not self.blank, label=capfirst(self.verbose_name), initial=initial, widget=self.widget) 617 617 618 618 class ManyToManyField(RelatedField, Field): 619 619 def __init__(self, to, **kwargs): … … 730 730 # MultipleChoiceField takes a list of IDs. 731 731 if initial is not None: 732 732 initial = [i._get_pk_val() for i in initial] 733 return forms.MultipleChoiceField(choices=self.get_choices_default(), required=not self.blank, label=capfirst(self.verbose_name), initial=initial )733 return forms.MultipleChoiceField(choices=self.get_choices_default(), required=not self.blank, label=capfirst(self.verbose_name), initial=initial, widget=self.widget) 734 734 735 735 class ManyToOneRel(object): 736 736 def __init__(self, to, field_name, num_in_admin=3, min_num_in_admin=None, -
django/newforms/fields.py
316 316 return bool(value) 317 317 318 318 class ChoiceField(Field): 319 def __init__(self, choices=(), required=True, widget=Select, label=None, initial=None): 319 widget = Select 320 def __init__(self, choices=(), required=True, widget=None, label=None, initial=None): 321 widget = widget or self.widget 320 322 if isinstance(widget, type): 321 323 widget = widget(choices=choices) 322 324 Field.__init__(self, required, widget, label, initial) … … 338 340 339 341 class MultipleChoiceField(ChoiceField): 340 342 hidden_widget = MultipleHiddenInput 343 widget = SelectMultiple 341 344 342 def __init__(self, choices=(), required=True, widget= SelectMultiple, label=None, initial=None):345 def __init__(self, choices=(), required=True, widget=None, label=None, initial=None): 343 346 ChoiceField.__init__(self, choices, required, widget, label, initial) 344 347 345 348 def clean(self, value):