Skip to content

Instantly share code, notes, and snippets.

@bencleary
Last active January 11, 2018 12:25
Show Gist options
  • Save bencleary/5ec0efa1e3e28f422bbcc4c433cb8113 to your computer and use it in GitHub Desktop.
Save bencleary/5ec0efa1e3e28f422bbcc4c433cb8113 to your computer and use it in GitHub Desktop.
DB Seeder
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