Ticket #17122: 2011.10.26_2020_EST.diff

File 2011.10.26_2020_EST.diff, 1.9 KB (added by nickname123, 13 years ago)

patch to add support for ForeignKey and ManyToMany relations

  • 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        value = rel_to._meta.pk.to_python(value)
    133137        if attrs is None:
    134138            attrs = {}
    135139        extra = []
     
    139143                                    (rel_to._meta.app_label,
    140144                                    rel_to._meta.module_name),
    141145                                    current_app=self.admin_site.name)
    142 
     146       
    143147            params = self.url_parameters()
    144148            if params:
    145149                url = u'?' + u'&'.join([u'%s=%s' % (k, v) for k, v in params.items()])
  • 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