Esempio n. 1
0
def create_book(title, author, pages, publish_date, publisher):
    book = Book()
    book.title = title
    book.author.append(author)
    book.pages = pages
    if publish_date:
        book.publish_date = publish_date
    book.publisher = publisher
    book.save()
    return book
Esempio n. 2
0
def create_book(num):
    books = []
    publishers = Publisher.objects()
    subscribers = Subscriber.objects()
    for i in range(num):
        book = Book()
        book.title = fake.sentence(nb_words=4)
        book.author.append(fake.name())
        book.pages = fake.pyint(min_value=100, max_value=600)
        book.publish_date = fake.date()
        book.publisher = random.choices(publishers)[0]
        borrow = Borrow()
        borrow.subscriber = random.choices(subscribers)[0]
        borrow.start = fake.date_object()
        borrow.end = borrow.start + datetime.timedelta(
            days=random.randint(14, 60))
        book.borrowing_history.append(borrow)
        books.append(book)
    return books