Django

Code

Changeset 6418

Show
Ignore:
Timestamp:
09/24/07 20:51:22 (1 year ago)
Author:
jkocherhans
Message:

newforms-admin: Fixed bug in many-to-many raw_id widget display.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • django/branches/newforms-admin/django/contrib/admin/widgets.py

    r6415 r6418  
    102102        if value: 
    103103            value = ','.join([str(v) for v in value]) 
    104         else:  
    105             value = "" 
     104        else: 
     105            value = '' 
    106106        return super(ManyToManyRawIdWidget, self).render(name, value, attrs) 
    107107 
    108108    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: 
    110111            return data[name].split(',') 
    111         return data.get(name, None) 
     112        if value: 
     113            return [value] 
     114        return None 
    112115 
    113116class RelatedFieldWidgetWrapper(object): 
  • django/branches/newforms-admin/django/newforms/models.py

    r6301 r6418  
    219219    provided. 
    220220    """ 
     221    # avoid a circular import 
     222    from django.db.models.fields.related import ManyToManyField 
    221223    model = instance.__class__ 
    222224    opts = model._meta 
     
    227229        if fields and not f.name in fields: 
    228230            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) 
    230236    return initial 
    231237