-
Notifications
You must be signed in to change notification settings - Fork 0
/
populate.py
42 lines (30 loc) · 994 Bytes
/
populate.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import os
import random
import django
from faker import Faker
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'Library_Management.settings')
django.setup()
from library.models import *
"""
Used to insert Fake data into Model
"""
def populate_data():
fake = Faker()
Faker.seed(0)
random.seed(0)
books = ['Physics', 'Chemistry', 'Maths', 'English']
for i in range(100):
name = fake.name()
pid = fake.numerify(text='######')
email = fake.email()
address = fake.address()
person = Person.objects.get_or_create(pid=pid, name=name, email=email, address=address)[0]
for i in range(50):
book = random.choice(books)
isbn = fake.numerify(text='#############')
author = fake.name()
publisher = fake.first_name()
book = Books.objects.get_or_create(name=book, isbn=isbn, author=author, publisher=publisher)[0]
# print(book, isbn, author, publisher)
populate_data()
print('DONE!!!!')