diff options
| author | Xavier Ordoquy | 2014-06-23 14:02:45 +0200 |
|---|---|---|
| committer | Xavier Ordoquy | 2014-06-23 14:02:45 +0200 |
| commit | 2489e38a06f575aa144644eee683bd87f20186ef (patch) | |
| tree | fc52fd2280d3ef6d0dc69d53a3771ee5f499ab29 /rest_framework/fields.py | |
| parent | 15c2c58b43a00ec29af99e0478b70eea57560fce (diff) | |
| parent | e11f41ebc4ef088a5849771dfda5a7fba4f82904 (diff) | |
| download | django-rest-framework-2489e38a06f575aa144644eee683bd87f20186ef.tar.bz2 | |
Merge remote-tracking branch 'origin/master' into 2.4.0
Conflicts:
.travis.yml
docs/api-guide/viewsets.md
rest_framework/serializers.py
rest_framework/throttling.py
tests/test_generics.py
tests/test_serializers.py
tox.ini
Diffstat (limited to 'rest_framework/fields.py')
| -rw-r--r-- | rest_framework/fields.py | 23 |
1 files changed, 16 insertions, 7 deletions
diff --git a/rest_framework/fields.py b/rest_framework/fields.py index 8eaf763d..e925c47e 100644 --- a/rest_framework/fields.py +++ b/rest_framework/fields.py @@ -64,7 +64,7 @@ def get_component(obj, attr_name): def readable_datetime_formats(formats): format = ', '.join(formats).replace(ISO_8601, - 'YYYY-MM-DDThh:mm[:ss[.uuuuuu]][+HHMM|-HHMM|Z]') + 'YYYY-MM-DDThh:mm[:ss[.uuuuuu]][+HH:MM|-HH:MM|Z]') return humanize_strptime(format) @@ -156,7 +156,12 @@ class Field(object): def widget_html(self): if not self.widget: return '' - return self.widget.render(self._name, self._value) + + attrs = {} + if 'id' not in self.widget.attrs: + attrs['id'] = self._name + + return self.widget.render(self._name, self._value, attrs=attrs) def label_tag(self): return '<label for="%s">%s:</label>' % (self._name, self.label) @@ -499,7 +504,7 @@ class SlugField(CharField): class ChoiceField(WritableField): type_name = 'ChoiceField' - type_label = 'multiple choice' + type_label = 'choice' form_field_class = forms.ChoiceField widget = widgets.Select default_error_messages = { @@ -507,12 +512,16 @@ class ChoiceField(WritableField): 'the available choices.'), } - def __init__(self, choices=(), *args, **kwargs): + def __init__(self, choices=(), blank_display_value=None, *args, **kwargs): self.empty = kwargs.pop('empty', '') super(ChoiceField, self).__init__(*args, **kwargs) self.choices = choices if not self.required: - self.choices = BLANK_CHOICE_DASH + self.choices + if blank_display_value is None: + blank_choice = BLANK_CHOICE_DASH + else: + blank_choice = [('', blank_display_value)] + self.choices = blank_choice + self.choices def _get_choices(self): return self._choices @@ -1016,9 +1025,9 @@ class SerializerMethodField(Field): A field that gets its value by calling a method on the serializer it's attached to. """ - def __init__(self, method_name): + def __init__(self, method_name, *args, **kwargs): self.method_name = method_name - super(SerializerMethodField, self).__init__() + super(SerializerMethodField, self).__init__(*args, **kwargs) def field_to_native(self, obj, field_name): value = getattr(self.parent, self.method_name)(obj) |
