示例#1
0
    def handle(self, *args, **options):
        batch_size = 5000
        book_cap, reader_cap = 100000, 50000
        mixer = Mixer(commit=False)

        books = mixer.cycle(book_cap).blend(Book)
        readers = mixer.cycle(reader_cap).blend(Reader)

        for i in range(0, reader_cap, batch_size):
            Reader.objects.bulk_create(readers[i:i + batch_size])

        for i in range(0, len(books), batch_size):
            Book.objects.bulk_create(books[i:i + batch_size])

        for book in books:
            index = random.randrange(1, reader_cap)
            book.readers.add(readers[index])
示例#2
0
def create_three_objects_of(model, common_data=None):
    if common_data is None:
        common_data = {}
    mixer = Mixer()
    return mixer.cycle(count=3).blend(model, **common_data)