[Answered ]-Django: How to make copy of one of the objects in the db

1👍

If the model has an autoincrement PK (the default) then you can create or retrieve the object once, then wipe the PK before saving it:

row = SomeModel(...)
for i in xrange(100:
  row.pk = None
  row.save()

1👍

# Create a bunch of new objects
for i in xrange(0,100):
    new_cat = Category(slug='a-slug', name="My Name")
    new_cat.save()

If you’re just looking to populate your database for testing purposes, you may want to look at using fixtures instead.

Leave a comment