docs: def todjango(table, model, update=True, create=True, use_bulk_create=True, *args, **kwargs):
      '''
      Given a table with appropriate headings create Django models.
      '''
      assert issubclass(model, Model), 'Must be supplied a valid Django model class'
      table_iterator = iter(table)
      table_headers = table_iterator.next()
  
      model_pk_field_name = model._meta.pk.name
      model_field_names = _get_model_field_names(model)
      model_name = model.__name__
  
      existing_models = _get_django_objects(model)
      existing_model_map = dict([(m.pk, m) for m in existing_models])
  
      if update:
          # if we are going to update existing models we need to have a table field that
          # corresponds to the model 'pk' field.
          assert model_pk_field_name in set(model_field_names), 'To be able to update existing models the data must have a field corresponding to the Django Primary Key field {}'.format(model_pk_field_name)
          # existing_model_pks = model.objects.all().values_list('pk', flat=True) # TODO: this could be a performance bottleneck if lots of models are being updated
  
      updated_model_count = 0
      unsaved_models = []
  
      for row in table_iterator:
          value_map = dict(zip(table_headers, row))
          pk = value_map.get(model_pk_field_name, None)
  
          try:
              django_object = existing_model_map[pk]
              if _will_model_change(value_map, django_object):
                  _apply_value_map(value_map, django_object)
                  try:
                      django_object.save()
                  except Exception as e:
                      # Add the data that cause the exception to the exception as reraise
                      e.petl_data = value_map
                      raise e
                  updated_model_count += 1
          except KeyError:
              django_object = model(**value_map)
              if use_bulk_create:
                  unsaved_models.append(django_object)
              else:
                  try:
                      django_object.save()
                  except Exception as e:
                      e.petl_data = value_map
                      raise e
      logger.debug('Bulk creating unsaved {}'.format(model_name))
      if use_bulk_create:
          _chunked_bulk_create(model, unsaved_models)
  
      msg = 'Updated {} existing {}'.format(updated_model_count, model_name)
      logger.info(msg)
  
      msg = 'Created {} new {}'.format(len(unsaved_models), model_name)
      logger.info(msg)