Ticket #17122: 2011.10.28_2206.diff

File 2011.10.28_2206.diff, 2.7 KB (added by nickname123, 3 years ago)

updated patch

  • django/contrib/admin/widgets.py

     
    130130
    131131    def render(self, name, value, attrs=None):
    132132        rel_to = self.rel.to
     133        # custom fields may need the to_python
     134        # conversion in order to facilitate
     135        # unicode conversion
     136        try:
     137            value = self.rel.to._meta.get_field(self.rel.field_name).to_python(value)
     138        except AttributeError:
     139            pass# 'ManyToManyRel' object has no attribute 'field_name'
    133140        if attrs is None:
    134141            attrs = {}
    135142        extra = []
     
    139146                                    (rel_to._meta.app_label,
    140147                                    rel_to._meta.module_name),
    141148                                    current_app=self.admin_site.name)
    142 
     149       
    143150            params = self.url_parameters()
    144151            if params:
    145152                url = u'?' + u'&'.join([u'%s=%s' % (k, v) for k, v in params.items()])
     
    248255
    249256    def render(self, name, value, *args, **kwargs):
    250257        rel_to = self.rel.to
     258        # custom fields may need the to_python
     259        # conversion in order to facilitate
     260        # unicode conversion
     261        try:
     262            value = self.rel.to._meta.get_field(self.rel.field_name).to_python(value)
     263        except AttributeError:
     264            pass# 'ManyToManyRel' object has no attribute 'field_name'
    251265        info = (rel_to._meta.app_label, rel_to._meta.object_name.lower())
    252266        self.widget.choices = self.choices
    253267        output = [self.widget.render(name, value, *args, **kwargs)]
  • django/forms/forms.py

     
    341341                    hidden_widget = field.hidden_widget()
    342342                    initial_value = hidden_widget.value_from_datadict(
    343343                        self.data, self.files, initial_prefixed_name)
     344                # custom fields may need the to_python
     345                # conversion in order to facilitate
     346                # unicode conversion
     347                if isinstance(initial_value,list):
     348                    # ManyToManyField uses a list
     349                    initial_value = [field.to_python(v) for v in initial_value]
     350                else:
     351                    initial_value = field.to_python(initial_value)
    344352                if field.widget._has_changed(initial_value, data_value):
    345353                    self._changed_data.append(name)
    346354        return self._changed_data
Back to Top