예제 #1
0
    def delete_batch(obj, pk_list, using, field=None):
        opts=obj.model._meta
        if not field:
            field = opts.pk

        # original batch delete iof not composite
        if not getattr(field, "is_composite_primarykeys_field", False):
            return original_delete_batch(obj, pk_list, using, field=field)

        # composite PK fields
        field_keys = field.fields

        for offset in range(0, len(pk_list), GET_ITERATOR_CHUNK_SIZE):
            where = obj.where_class()
            off_list = pk_list[offset : offset + GET_ITERATOR_CHUNK_SIZE]

            # delete where in using concatenate features
            values = [disassemble_pk(value, len(field_keys)) for value in off_list]
            values = [[field.get_prep_value(part) for field, part in zip(field_keys, value)] for value in values]
            where.add(MultipleColumnsIN([f.column for f in field_keys], values), AND)

            obj.do_query(obj.model._meta.db_table, where, using=using)
예제 #2
0
 def natural_key(self):
     return disassemble_pk(
         self.pk,
         len(self._meta.composite_primarykeys_field.fields))
예제 #3
0
 def natural_key(self):
     return disassemble_pk(self.pk, len(self._meta.composite_primarykeys_field.fields))