Add fake data
This commit is contained in:
24
scripts/create_books.py
Normal file
24
scripts/create_books.py
Normal file
@ -0,0 +1,24 @@
|
||||
from app.library.models import Book
|
||||
import json
|
||||
|
||||
def run():
|
||||
|
||||
print('Working')
|
||||
|
||||
# Delete old books
|
||||
Book.objects.all().delete()
|
||||
|
||||
# Read file
|
||||
with open("scripts/example_books.json", "r") as file_books:
|
||||
books = json.loads(file_books.read())
|
||||
|
||||
# Create books
|
||||
for book in books:
|
||||
Book(
|
||||
title=book['title'],
|
||||
author=book['author'],
|
||||
country=book['country'],
|
||||
year=book['year'],
|
||||
).save()
|
||||
|
||||
print('Finish!')
|
Reference in New Issue
Block a user