Ticket #2243: django_2243b.patch
File django_2243b.patch, 5.4 KB (added by , 18 years ago) |
---|
-
django/db/models/fields/related.py
2 2 from django.db.models import signals, get_model 3 3 from django.db.models.fields import AutoField, Field, IntegerField, get_ul_class 4 4 from django.db.models.related import RelatedObject 5 from django.utils.translation import gettext_lazy, string_concat 5 from django.utils.translation import gettext_lazy, string_concat, ngettext 6 6 from django.utils.functional import curry 7 7 from django.core import validators 8 8 from django import forms … … 671 671 new_data = {} 672 672 if obj: 673 673 instance_ids = [instance._get_pk_val() for instance in getattr(obj, self.name).all()] 674 if self.rel.raw_id_admin: 675 new_data[self.name] = ",".join([str(id) for id in instance_ids]) 676 else: 677 new_data[self.name] = instance_ids 674 new_data[self.name] = instance_ids 678 675 else: 679 676 # In required many-to-many fields with only one available choice, 680 677 # select that one available choice. -
django/db/models/manipulators.py
115 115 # Save many-to-many objects. Example: Set sites for a poll. 116 116 for f in self.opts.many_to_many: 117 117 if self.follow.get(f.name, None): 118 if not f.rel.edit_inline: 119 if f.rel.raw_id_admin: 120 new_vals = new_data.get(f.name, ()) 121 else: 122 new_vals = new_data.getlist(f.name) 118 if not f.rel.edit_inline: 119 # PATCH for 2243: M2M fields give list regardless of raw_id_admin 120 new_vals = new_data.getlist(f.name) 123 121 # First, clear the existing values. 124 122 rel_manager = getattr(new_object, f.name) 125 123 rel_manager.clear() … … 212 210 if not f.primary_key and f != related.field and str(getattr(old_rel_obj, f.attname)) != str(getattr(new_rel_obj, f.attname)): 213 211 self.fields_changed.append('%s for %s "%s"' % (f.verbose_name, related.opts.verbose_name, new_rel_obj)) 214 212 215 # Save many-to-many objects. 216 for f in related.opts.many_to_many: 217 if child_follow.get(f.name, None) and not f.rel.edit_inline: 218 was_changed = getattr(new_rel_obj, 'set_%s' % f.name)(rel_new_data[f.attname]) 219 if self.change and was_changed: 220 self.fields_changed.append('%s for %s "%s"' % (f.verbose_name, related.opts.verbose_name, new_rel_obj)) 213 # Save many-to-many objects - PATCH FOR 2243 214 for f in related.opts.many_to_many: 215 if child_follow.get(f.name, None) and not f.rel.edit_inline: 216 new_vals = rel_new_data.get(f.name, ()) 217 # First, clear the existing values. 218 rel_manager = getattr(new_rel_obj, f.name) 219 rel_manager.clear() 220 # Then, set the new values. 221 for n in new_vals: 222 rel_manager.add(f.rel.to._default_manager.get(pk=n)) 223 # TODO: Add to 'fields_changed' 221 224 222 225 # If, in the change stage, all of the core fields were blank and 223 226 # the primary key (ID) was provided, delete the item. -
django/forms/__init__.py
971 971 raise validators.CriticalValidationError, e.messages 972 972 973 973 class RawIdAdminField(CommaSeparatedIntegerField): 974 # well, renderer should see data as LIST... 975 requires_data_list = True 976 977 # ... whereas validators are to see it as STRING 978 def run_validator(self, new_data, validator): 979 if self.is_required or new_data.get(self.field_name, False) or hasattr(validator, 'always_test'): 980 validator(new_data.get(self.field_name, ''), new_data) 981 982 # here we change actual data from STRING to LIST 983 def convert_post_data(self, new_data): 984 name = self.get_member_name() 985 if new_data.has_key(self.field_name): 986 d = new_data[self.field_name] 987 converted_data = self.__class__.html2python(d) 988 new_data.setlist(name, converted_data) 989 else: 990 new_data.setlist(name, []) 991 974 992 def html2python(data): 975 993 return data.split(',') 976 994 html2python = staticmethod(html2python) 977 995 996 def render(self, data): 997 # it HAS to be list, but just in case... 998 if isinstance(data, list): 999 data = ','.join(str(d) for d in data) 1000 return TextField.render(self, data) 1001 978 1002 class XMLLargeTextField(LargeTextField): 979 1003 """ 980 1004 A LargeTextField with an XML validator. The schema_path argument is the