/
populate.py
104 lines (84 loc) · 2.95 KB
/
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
import os
import datetime
import django
def populate():
rover = Dog(name='Rover',
owner='Beatriz',
breed='Doberman Pinscher',
birthday=datetime.date(2014,1,3))
rover.save()
sue = Dog(name='Sue',
owner='Beatriz',
breed='Chihuahua',
birthday=datetime.date(2011,7,1))
sue.save()
miles = Dog(name='Miles',
owner='Maite',
breed='German Shepherd',
birthday=datetime.date(2010,4,12))
miles.save()
appointment_1 = Appointment(
time=datetime.datetime(2015,9,12,8,30),
dog_walked=rover)
appointment_1.save()
appointment_2 = Appointment(
time=datetime.datetime(2015,9,13,8,30),
dog_walked=rover)
appointment_2.save()
appointment_3 = Appointment(
time=datetime.datetime(2015,9,14,8,30),
dog_walked=rover)
appointment_3.save()
appointment_4 = Appointment(
time=datetime.datetime(2015,9,15,8,30),
dog_walked=rover)
appointment_4.save()
appointment_5 = Appointment(
time=datetime.datetime(2015,9,16,8,30),
dog_walked=rover)
appointment_5.save()
appointment_6 = Appointment(
time=datetime.datetime(2015,10,1,11,00),
dog_walked=miles)
appointment_6.save()
appointment_7 = Appointment(
time=datetime.datetime(2015,10,3,11,00),
dog_walked=miles)
appointment_7.save()
wiggly_walkers = add_business('Wiggly Walkers')
add_walker(business='Wiggly Walkers', walker_name='Alfredo')
add_walker(business='Wiggly Walkers', walker_name='Adelaide')
add_walker(business='Wiggly Walkers', walker_name='Anton')
we_walk_your_pup = add_business('We Walk Your Pup')
add_walker('We Walk Your Pup', walker_name='Camille')
add_walker('We Walk Your Pup', walker_name='Carine')
add_walker('We Walk Your Pup', walker_name='Bruno')
pups_ahoy = add_business('Pups Ahoy')
add_walker('Pups Ahoy', walker_name='Diane')
add_walker('Pups Ahoy', walker_name='Estelle')
add_walker('Pups Ahoy', walker_name='Eric')
for b in Business.objects.all():
for w in Walker.objects.filter(business=b):
print ("- {0} - {1}".format(str(b), str(w)))
for d in Dog.objects.all():
print(d)
for a in Appointment.objects.all():
print(a)
def add_business(business):
b = Business.objects.get_or_create(business_name=business)
return b
def add_walker(business, walker_name):
b, created = Business.objects.get_or_create(business_name=business)
if created:
b.save()
w = Walker(walker_name=walker_name, business=b)
w.save()
return w
def add_dog(name, owner, breed, birthday):
name = Dog.objects.get_or_create(name=name)
if __name__ == '__main__':
print('Starting Biscuit population script...')
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'superbiscuit.settings')
django.setup()
from biscuit.models import Business, Walker, Dog, Appointment
populate()