def create_publishers(num): publishers = [] for i in range(num): publisher = Publisher() publisher.name = fake.name() publisher.founded = fake.date() publisher.location = fake.address() publishers.append(publisher) return publishers
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
def create_publisher(name, founded, location): publisher = Publisher(name=name, founded=founded, location=location).save() return publisher
def get_publisher(publisher): publisher = Publisher.objects(id=publisher).first() return publisher
def list_publisher(): publisher = Publisher.objects() return publisher