mirror of
https://github.com/django/django.git
synced 2025-07-04 09:49:12 +00:00
newforms-admin: Fixed bug in many-to-many raw_id widget display.
git-svn-id: http://code.djangoproject.com/svn/django/branches/newforms-admin@6418 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
parent
609eaf130d
commit
9687447e31
@ -101,14 +101,17 @@ class ManyToManyRawIdWidget(ForeignKeyRawIdWidget):
|
||||
attrs['class'] = 'vManyToManyRawIdAdminField'
|
||||
if value:
|
||||
value = ','.join([str(v) for v in value])
|
||||
else:
|
||||
value = ""
|
||||
else:
|
||||
value = ''
|
||||
return super(ManyToManyRawIdWidget, self).render(name, value, attrs)
|
||||
|
||||
def value_from_datadict(self, data, files, name):
|
||||
if isinstance(data, MultiValueDict):
|
||||
value = data.get(name, None)
|
||||
if value and ',' in value:
|
||||
return data[name].split(',')
|
||||
return data.get(name, None)
|
||||
if value:
|
||||
return [value]
|
||||
return None
|
||||
|
||||
class RelatedFieldWidgetWrapper(object):
|
||||
"""
|
||||
|
@ -218,6 +218,8 @@ def initial_data(instance, fields=None):
|
||||
All field values in the instance will be returned if ``fields`` is not
|
||||
provided.
|
||||
"""
|
||||
# avoid a circular import
|
||||
from django.db.models.fields.related import ManyToManyField
|
||||
model = instance.__class__
|
||||
opts = model._meta
|
||||
initial = {}
|
||||
@ -226,7 +228,11 @@ def initial_data(instance, fields=None):
|
||||
continue
|
||||
if fields and not f.name in fields:
|
||||
continue
|
||||
initial[f.name] = f.value_from_object(instance)
|
||||
if isinstance(f, ManyToManyField):
|
||||
# MultipleChoiceWidget needs a list of ints, not object instances.
|
||||
initial[f.name] = [obj._get_pk_val() for obj in f.value_from_object(instance)]
|
||||
else:
|
||||
initial[f.name] = f.value_from_object(instance)
|
||||
return initial
|
||||
|
||||
class BaseModelFormSet(BaseFormSet):
|
||||
|
Loading…
x
Reference in New Issue
Block a user