Beispiel #1
0
    'Myron Cohen', 'Felipe Tucker', 'Inez Perry', 'Darlene Cruz'
]

monkeys = list()

for name in names:
    name_split = name.split()
    monkey = Monkey(
        name_split[0], name_split[1], '123',
        name_split[0].lower() + '.' + name_split[1].lower() + '@email.com',
        str(random.randint(1950, 2014)) + '-' + str(random.randint(1, 12)) +
        '-' + str(random.randint(1, 28)))
    monkeys.append(monkey)

for monkey in monkeys:
    db.session.add(monkey)

    # Up to 20 friends
    for i in range(random.randint(0, 20)):
        potential_friend = monkeys[random.randint(0, len(monkeys) - 1)]
        if potential_friend is not monkey and \
            potential_friend not in monkey.friends:
            monkey.friends.append(potential_friend)

    # 2:1 chance of having a best friend
    if monkey.friends and random.randint(0, 2):
        monkey.best_friend = \
            monkey.friends[random.randint(0, len(monkey.friends) - 1)]

db.session.commit()
Beispiel #2
0
"""
Initial test data.
"""

# >>> exec(open("db_initial.py").read())

from MonkeyBook.models import db
from MonkeyBook.models import Monkey

db.drop_all()
db.create_all()

jack = Monkey('Jack', 'Jones', '123', '*****@*****.**', '1980-02-03')
jill = Monkey('Jill', 'Jones','321', '*****@*****.**')
john = Monkey('John', 'Doe', '456', '*****@*****.**', '1981-10-19')

db.session.add(jack)
db.session.add(jill)
db.session.add(john)

jill.friends.append(jack)
jack.friends.append(jill)
jack.friends.append(john)
john.friends.append(jack)
john.friends.append(jill)

jack.best_friend = jill
john.best_friend = jack

db.session.commit()
Beispiel #3
0
"""
Initial test data.
"""

# >>> exec(open("db_initial.py").read())

from MonkeyBook.models import db
from MonkeyBook.models import Monkey

db.drop_all()
db.create_all()

jack = Monkey('Jack', 'Jones', '123', '*****@*****.**', '1980-02-03')
jill = Monkey('Jill', 'Jones', '321', '*****@*****.**')
john = Monkey('John', 'Doe', '456', '*****@*****.**', '1981-10-19')

db.session.add(jack)
db.session.add(jill)
db.session.add(john)

jill.friends.append(jack)
jack.friends.append(jill)
jack.friends.append(john)
john.friends.append(jack)
john.friends.append(jill)

jack.best_friend = jill
john.best_friend = jack

db.session.commit()
Beispiel #4
0
monkeys = list()

for name in names:
    name_split = name.split()
    monkey = Monkey(name_split[0],
                    name_split[1],
                    '123',
                    name_split[0].lower() +
                        '.' + name_split[1].lower() + '@email.com',
                    str(random.randint(1950, 2014)) + '-' +
                        str(random.randint(1, 12)) + '-' +
                        str(random.randint(1, 28)))
    monkeys.append(monkey)

for monkey in monkeys:
    db.session.add(monkey)

    # Up to 20 friends
    for i in range(random.randint(0, 20)):
        potential_friend = monkeys[random.randint(0, len(monkeys) - 1)]
        if potential_friend is not monkey and \
            potential_friend not in monkey.friends:
                monkey.friends.append(potential_friend)

    # 2:1 chance of having a best friend
    if monkey.friends and random.randint(0, 2):
        monkey.best_friend = \
            monkey.friends[random.randint(0, len(monkey.friends) - 1)]

db.session.commit()