mirror of
https://github.com/django/django.git
synced 2025-07-05 02:09:13 +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
@ -102,13 +102,16 @@ class ManyToManyRawIdWidget(ForeignKeyRawIdWidget):
|
|||||||
if value:
|
if value:
|
||||||
value = ','.join([str(v) for v in value])
|
value = ','.join([str(v) for v in value])
|
||||||
else:
|
else:
|
||||||
value = ""
|
value = ''
|
||||||
return super(ManyToManyRawIdWidget, self).render(name, value, attrs)
|
return super(ManyToManyRawIdWidget, self).render(name, value, attrs)
|
||||||
|
|
||||||
def value_from_datadict(self, data, files, name):
|
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[name].split(',')
|
||||||
return data.get(name, None)
|
if value:
|
||||||
|
return [value]
|
||||||
|
return None
|
||||||
|
|
||||||
class RelatedFieldWidgetWrapper(object):
|
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
|
All field values in the instance will be returned if ``fields`` is not
|
||||||
provided.
|
provided.
|
||||||
"""
|
"""
|
||||||
|
# avoid a circular import
|
||||||
|
from django.db.models.fields.related import ManyToManyField
|
||||||
model = instance.__class__
|
model = instance.__class__
|
||||||
opts = model._meta
|
opts = model._meta
|
||||||
initial = {}
|
initial = {}
|
||||||
@ -226,7 +228,11 @@ def initial_data(instance, fields=None):
|
|||||||
continue
|
continue
|
||||||
if fields and not f.name in fields:
|
if fields and not f.name in fields:
|
||||||
continue
|
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
|
return initial
|
||||||
|
|
||||||
class BaseModelFormSet(BaseFormSet):
|
class BaseModelFormSet(BaseFormSet):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user