Changeset 6418
- Timestamp:
- 09/24/07 20:51:22 (1 year ago)
- Files:
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
django/branches/newforms-admin/django/contrib/admin/widgets.py
r6415 r6418 102 102 if value: 103 103 value = ','.join([str(v) for v in value]) 104 else: 105 value = ""104 else: 105 value = '' 106 106 return super(ManyToManyRawIdWidget, self).render(name, value, attrs) 107 107 108 108 def value_from_datadict(self, data, files, name): 109 if isinstance(data, MultiValueDict): 109 value = data.get(name, None) 110 if value and ',' in value: 110 111 return data[name].split(',') 111 return data.get(name, None) 112 if value: 113 return [value] 114 return None 112 115 113 116 class RelatedFieldWidgetWrapper(object): django/branches/newforms-admin/django/newforms/models.py
r6301 r6418 219 219 provided. 220 220 """ 221 # avoid a circular import 222 from django.db.models.fields.related import ManyToManyField 221 223 model = instance.__class__ 222 224 opts = model._meta … … 227 229 if fields and not f.name in fields: 228 230 continue 229 initial[f.name] = f.value_from_object(instance) 231 if isinstance(f, ManyToManyField): 232 # MultipleChoiceWidget needs a list of ints, not object instances. 233 initial[f.name] = [obj._get_pk_val() for obj in f.value_from_object(instance)] 234 else: 235 initial[f.name] = f.value_from_object(instance) 230 236 return initial 231 237
