Commit d9cb7034 authored by lizonr1's avatar lizonr1

Add init scripts

parent 038fd0cf
from django.contrib.auth.models import User
from App.loyaltyMe.models import Offer, Product
__author__ = 'Rafal'
from django.core.management.base import BaseCommand, CommandError
class Command(BaseCommand):
help = 'Closes the specified poll for voting'
def handle(self, *args, **options):
offers = [
#'name',products
['Oferta1', ['Kawa Latte', 'Herbata'] ],
['Oferta2', ['Ciasto', 'Espresso'] ],
]
print("Creating Offers")
for offer in offers:
print('Create {0}'.format(offer[0]))
new_offer = Offer.objects.create(name=offer[0])
for product in offer[1]:
print(product)
pro_obj = Product.objects.filter(name=product)[0]
new_offer.products.add(pro_obj)
new_offer.save()
\ No newline at end of file
from App.loyaltyMe.models import Place
from App.loyaltyMe.models import Place, Offer, Promotion
__author__ = 'Rafal'
from django.core.management.base import BaseCommand, CommandError
......@@ -9,11 +9,15 @@ class Command(BaseCommand):
def handle(self, *args, **options):
places = [
#['name', 'type', 'screen_img', 'logo_img', 'description', 'offer', 'promotions'],
['Kocia Kawiarnia', 'Cafeteria', '/static/media/img/photo_1.jpg', '/static/media/img/photo_1.jpg', 'description', None, None],
['Kafcia u Olczaka', 'Cafeteria', '/static/media/img/photo_1.jpg', '/static/media/img/photo_1.jpg', 'description', None, None],
['Kocia Kawiarnia', 'Cafeteria', '/static/media/img/photo_1.jpg', '/static/media/img/photo_1.jpg', 'description', 'Oferta1', ['10%','20%']],
['Kafcia u Olczaka', 'Cafeteria', '/static/media/img/photo_1.jpg', '/static/media/img/photo_1.jpg', 'description', 'Oferta2', ['20%','50%']],
]
print("Creating Places")
for place in places:
print('Create {0}'.format(place[0]))
new_place = Place.objects.create(name=place[0], type=place[1], screen_img=place[2], logo_img=place[3], description=place[4], offer=place[5], promotions = place[6])
offer = Offer.objects.filter(name=place[5])[0]
new_place = Place.objects.create(name=place[0], type=place[1], screen_img=place[2], logo_img=place[3], description=place[4], offer=offer)
for promotion in place[6]:
prom_obj = Promotion.objects.filter(name=promotion)[0]
new_place.promotions.add(prom_obj)
new_place.save()
\ No newline at end of file
......@@ -31,4 +31,4 @@ class Place(models.Model):
logo_img = models.ImageField()
description = models.CharField(max_length=50)
offer = models.ForeignKey(Offer, null=True, blank=True)
promotions = models.ForeignKey(Promotion, null=True, blank=True)
promotions = models.ManyToManyField(Promotion, null=True, blank=True)
......@@ -8,4 +8,8 @@ class Command(BaseCommand):
def handle(self, *args, **options):
call_command('init_users')
call_command('init_products')
call_command('init_offers')
call_command('init_promotions')
call_command('init_places')
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment