Last active
January 11, 2018 12:25
-
-
Save bencleary/5ec0efa1e3e28f422bbcc4c433cb8113 to your computer and use it in GitHub Desktop.
DB Seeder
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from .models import * | |
from random import * | |
from decimal import Decimal | |
class Seeder: | |
def __init__(self): | |
self.products = ["Orange Ball", "Chew Toy 1", "Cat Bowl", "Dog Bed", "Cat Food", "Dog Food"] | |
def seed(self): | |
for x in range(20): | |
title = choice(self.products) + " {0}".format(randint(1, 10000)) | |
price = float(format(Decimal(str(random())), '.2f')) | |
quantity = randint(1, 100) | |
customer = User.objects.get(pk=randint(1,3)) | |
product = Products(title=title, price=price) | |
product.save() | |
sale = Sales(product=product, quantity=quantity, customer=customer) | |
sale.save() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment