Commit 15ef41dc authored by lizonr1's avatar lizonr1

Add promotionssets and new data

parent fb50e22d
from App.loyaltyMe.models import Place, Offer, Promotion
from App.loyaltyMe.models import Place, Offer, Promotion, PromotionSet
__author__ = 'Rafal'
from django.core.management.base import BaseCommand, CommandError
......@@ -9,15 +9,17 @@ 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', 'Oferta1', ['10%','20%']],
['Kafcia u Olczaka', 'Cafeteria', '/static/media/img/photo_1.jpg', '/static/media/img/photo_1.jpg', 'description', 'Oferta2', ['20%','50%']],
['Kocia Kawiarnia', 'Cafeteria', '/static/media/img/photo_1.jpg', '/static/media/img/photo_1.jpg', 'description', 'Oferta1', 'Promocja1' ],
['Kafcia u Olczaka', 'Cafeteria', '/static/media/img/photo_1.jpg', '/static/media/img/photo_1.jpg', 'description', 'Oferta2', 'Promocja2'],
['Psia Kawiarnia', 'Cafeteria', '/static/media/img/photo_1.jpg', '/static/media/img/photo_1.jpg', 'description', 'Oferta1', 'Promocja1' ],
['Kafcia u Iwczaka', 'Cafeteria', '/static/media/img/photo_1.jpg', '/static/media/img/photo_1.jpg', 'description', 'Oferta2', 'Promocja2'],
['Lemingowa Kawiarnia', 'Cafeteria', '/static/media/img/photo_1.jpg', '/static/media/img/photo_1.jpg', 'description', 'Oferta1', 'Promocja1' ],
['Kafcia u Ewelinczaka', 'Cafeteria', '/static/media/img/photo_1.jpg', '/static/media/img/photo_1.jpg', 'description', 'Oferta2', 'Promocja2'],
]
print("Creating Places")
for place in places:
print('Create {0}'.format(place[0]))
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)
promotion_set = PromotionSet.objects.filter(name=place[6])[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, promotion=promotion_set)
new_place.save()
\ No newline at end of file
from django.contrib.auth.models import User
from App.loyaltyMe.models import PromotionSet, Promotion
__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):
promotion_sets = [
#'name',products
['Promocja1', ['10%', '20%'] ],
['Promocja2', ['20%', '50%'] ],
]
print("Creating PromotionSets")
for promotion_set in promotion_sets:
print('Create {0}'.format(promotion_set[0]))
new_promotion_set = PromotionSet.objects.create(name=promotion_set[0])
for product in promotion_set[1]:
print(product)
pro_obj = Promotion.objects.filter(name=product)[0]
new_promotion_set.promotions.add(pro_obj)
new_promotion_set.save()
\ No newline at end of file
......@@ -23,6 +23,9 @@ class Promotion(models.Model):
img = models.ImageField()
status = models.CharField(max_length=50)
class PromotionSet(models.Model):
name = models.CharField(max_length=50)
promotions = models.ManyToManyField(Promotion, default='')
class Place(models.Model):
name = models.CharField(max_length=50, unique=True)
......@@ -31,4 +34,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.ManyToManyField(Promotion, default='')
promotion = models.ForeignKey(PromotionSet, null=True, blank=True)
......@@ -9,16 +9,28 @@ class ProductSerializer(serializers.HyperlinkedModelSerializer):
fields = ('url', 'id', 'name', 'description', 'price', 'img')
class OfferSerializer(serializers.HyperlinkedModelSerializer):
products = ProductSerializer(many=True)
class Meta:
model = Offer
fields = ('url', 'id', 'products')
class PromotionSerializer(serializers.HyperlinkedModelSerializer):
class Meta:
model = Promotion
fields = ('url', 'id', 'name', 'description', 'code', 'img', 'status')
class PromotionSetSerializer(serializers.HyperlinkedModelSerializer):
promotions = PromotionSerializer(many=True)
class Meta:
model = Offer
fields = ('url', 'id', 'promotions')
class PlaceSerializer(serializers.HyperlinkedModelSerializer):
offer = OfferSerializer()
promotion = PromotionSetSerializer()
class Meta:
model = Place
fields = ('url', 'id', 'name', 'type', 'screen_img', 'logo_img', 'description', 'offer', 'promotions')
\ No newline at end of file
fields = ('url', 'id', 'name', 'type', 'screen_img', 'logo_img', 'description', 'offer', 'promotion')
\ No newline at end of file
......@@ -2,8 +2,9 @@ from django.shortcuts import render
from rest_framework import viewsets, permissions
from rest_framework.decorators import list_route
from App.loyaltyMe.models import Product, Offer, Promotion, Place
from App.loyaltyMe.serializers import ProductSerializer, OfferSerializer, PromotionSerializer, PlaceSerializer
from App.loyaltyMe.models import Product, Offer, Promotion, Place, PromotionSet
from App.loyaltyMe.serializers import ProductSerializer, OfferSerializer, PromotionSerializer, PlaceSerializer, \
PromotionSetSerializer
class ProductViewSet(viewsets.ModelViewSet):
......@@ -30,6 +31,16 @@ class PromotionViewSet(viewsets.ModelViewSet):
serializer_class = PromotionSerializer
permission_classes = (permissions.IsAuthenticatedOrReadOnly,)
class PromotionSetViewSet(viewsets.ModelViewSet):
"""
API for articles
"""
queryset = PromotionSet.objects.all()
serializer_class = PromotionSetSerializer
permission_classes = (permissions.IsAuthenticatedOrReadOnly,)
class PlaceViewSet(viewsets.ModelViewSet):
"""
API for articles
......
......@@ -11,5 +11,6 @@ class Command(BaseCommand):
call_command('init_products')
call_command('init_offers')
call_command('init_promotions')
call_command('init_promotionsets')
call_command('init_places')
......@@ -28,6 +28,7 @@ router.register(r'user', user_views.UserViewSet)
router.register(r'products', loyalty_views.ProductViewSet)
router.register(r'offerts', loyalty_views.OfferViewSet)
router.register(r'promotions', loyalty_views.PromotionViewSet)
router.register(r'promotion_set', loyalty_views.PromotionSetViewSet)
router.register(r'places', loyalty_views.PlaceViewSet)
urlpatterns = [
......
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