Skip to content

Instantly share code, notes, and snippets.

View sutyrin's full-sized avatar

Pavel Sutyrin sutyrin

View GitHub Profile
@sutyrin
sutyrin / BulkInsertManager.py
Created June 30, 2017 09:18 — forked from datamafia/BulkInsertManager.py
Django Bulk Insert Manager for ON DUPLICATE IGNORE and ON DUPLICATE KEY in MySQL
#!/usr/bin/env python
# marc-w.com
# Built and tested on Django 1.5
class BulkInsertManager(models.Manager):
def _bulk_insert_ignore(self, create_fields, values, print_sql=False):
'''
Bulk insert/ignore
@param create_fields : list, required, fields for the insert field declaration
class Graph:
def __init__(self):
self.nodes = set()
self.edges = defaultdict(list)
self.distances = {}
def add_node(self, value):
self.nodes.add(value)
def add_edge(self, from_node, to_node, distance):