-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpopulate_app1.py
More file actions
38 lines (27 loc) · 963 Bytes
/
populate_app1.py
File metadata and controls
38 lines (27 loc) · 963 Bytes
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
import os
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'djangofirstone.settings')
import django
django.setup()
import random
from app1.models import Topic, Webpage, AccessRecord
from faker import Faker
fakegen = Faker()
topics = ['Search', 'Social', 'Marketplace', 'News', 'Games']
def add_topic():
t = Topic.objects.get_or_create(top_name=random.choice(topics))[0]
t.save()
return t
def populate(N=5):
for entry in range(N):
top = add_topic()
fake_url = fakegen.url()
fake_date = fakegen.date()
fake_name = fakegen.company()
webpg = Webpage.objects.get_or_create(topic=top, url=fake_url,
name=fake_name)[0]
acc_rec = AccessRecord.objects.get_or_create(name=webpg,
date=fake_date)[0]
if __name__ == '__main__':
print("populating script")
populate()
print("populating done")