Ticket #2243: django_2243.patch
File django_2243.patch, 4.2 KB (added by , 18 years ago) |
---|
-
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 -
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. -
forms/__init__.py
971 971 raise validators.CriticalValidationError, e.messages 972 972 973 973 class RawIdAdminField(CommaSeparatedIntegerField): 974 # we need to overload this. Why? Because we're transforming a SINGLE field to a LIST! 975 # and we don't wanna end up having LIST of LISTS 976 def convert_post_data(self, new_data): 977 name = self.get_member_name() 978 if new_data.has_key(self.field_name): 979 d = new_data[self.field_name] 980 converted_data = self.__class__.html2python(d) 981 new_data.setlist(name, converted_data) 982 else: 983 new_data.setlist(name, []) 984 974 985 def html2python(data): 975 986 return data.split(',') 976 987 html2python = staticmethod(html2python)