Ticket #1334: manipulators.patch

File manipulators.patch, 1.4 KB (added by limodou@…, 9 years ago)
  • fields/related.py

     
    127127        (rel_col_name, join_table, this_col_name,
    128128        rel_col_name, ",".join(['%s'] * len(new_ids))),
    129129        [this_pk_val] + list(new_ids))
    130     existing_ids = set([row[0] for row in cursor.fetchmany(rowcount)])
     130    if rowcount:
     131        existing_ids = set([row[0] for row in cursor.fetchmany(rowcount)])
     132    else:
     133        existing_ids = set()
    131134
    132135    # Add the ones that aren't there already
    133136    for obj_id in (new_ids - existing_ids):
  • manipulators.py

     
    119119                        new_vals = new_data.get(f.name, ())
    120120                    else:
    121121                        new_vals = new_data.getlist(f.name)
    122                     was_changed = getattr(new_object, 'set_%s' % f.name)(new_vals)
     122#                    was_changed = getattr(new_object, 'set_%s' % f.name)(new_vals)
     123                    getattr(new_object, f.name).clear()
     124                    was_changed = getattr(new_object, f.name).add(*f.rel.to.objects.filter(id__in=new_vals))
     125#chang end
    123126                    if self.change and was_changed:
    124127                        self.fields_changed.append(f.verbose_name)
    125128
Back to Top