Overcome the bulk_create() size limitation using SQLite

1
2
3
4
5
6
def safe_bulk_create(objs):
    """Wrapper to overcome the size limitation of standard bulk_create()"""
    if objs:
        BULK_SIZE = 900/len(objs[0].__class__._meta.fields)
        for i in range(0,len(objs),BULK_SIZE):
            objs[0].__class__.objects.bulk_create(objs[i:i+BULK_SIZE])

More like this

  1. Bulk Insert - updated 5/9/2008 by coolie 5 years, 7 months ago
  2. Template tag to create a list from one or more variables and/or literals by davidchambers 2 years, 8 months ago
  3. Password Validation - Require Letters and Numbers - no regex by watchedman 1 year, 8 months ago
  4. PositionField by jpwatts 4 years, 10 months ago
  5. Significant digits filter by joelegner 4 years, 2 months ago

Comments

(Forgotten your password?)