Commit a5264315 authored by Rafal's avatar Rafal

Add localization

parent d903ec8a
from django.contrib.auth.models import User
from App.loyaltyMe.models import Offer, Product, Localization
__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):
localizations = [
['0.0000', '10.0000', 'Kraków', 'Makowicka', '55' ],
['10.0000', '0.0000', 'Kraków', 'Rynek', '15' ],
]
print("Creating Localizations")
for localization in localizations:
print('Create {0}'.format(localization[0]))
new_localization = Localization.objects.create(latitude=localization[0], longitude=localization[1], city=localization[2], road=localization[3], road_number =localization[4])
new_localization.save()
\ No newline at end of file
from App.loyaltyMe.models import Place, Offer, Promotion, PromotionSet from App.loyaltyMe.models import Place, Offer, Promotion, PromotionSet, Localization
__author__ = 'Rafal' __author__ = 'Rafal'
from django.core.management.base import BaseCommand, CommandError from django.core.management.base import BaseCommand, CommandError
...@@ -9,17 +9,18 @@ class Command(BaseCommand): ...@@ -9,17 +9,18 @@ class Command(BaseCommand):
def handle(self, *args, **options): def handle(self, *args, **options):
places = [ places = [
#['name', 'type', 'screen_img', 'logo_img', 'description', 'offer', 'promotions'], #['name', 'type', 'screen_img', 'logo_img', 'description', 'offer', 'promotions'],
['Kocia Kawiarnia', 'Cafeteria', '/static/img/photo_1.jpg', '/static/img/photo_1.jpg', 'description', 'Oferta1', 'Promocja1' ], ['Kocia Kawiarnia', 'Cafeteria', '/static/img/photo_1.jpg', '/static/img/photo_1.jpg', 'description', 'Oferta1', 'Promocja1' , 'Makowicka'],
['Kafcia u Olczaka', 'Cafeteria', '/static/img/photo_1.jpg', '/static/img/photo_1.jpg', 'description', 'Oferta2', 'Promocja2'], ['Kafcia u Olczaka', 'Cafeteria', '/static/img/photo_1.jpg', '/static/img/photo_1.jpg', 'description', 'Oferta2', 'Promocja2' ,'Makowicka'],
['Psia Kawiarnia', 'Cafeteria', '/static/img/photo_1.jpg', '/static/img/photo_1.jpg', 'description', 'Oferta1', 'Promocja1' ], ['Psia Kawiarnia', 'Cafeteria', '/static/img/photo_1.jpg', '/static/img/photo_1.jpg', 'description', 'Oferta1', 'Promocja1', 'Rynek' ],
['Kafcia u Iwczaka', 'Cafeteria', '/static/img/photo_1.jpg', '/static/img/photo_1.jpg', 'description', 'Oferta2', 'Promocja2'], ['Kafcia u Iwczaka', 'Cafeteria', '/static/img/photo_1.jpg', '/static/img/photo_1.jpg', 'description', 'Oferta2', 'Promocja2', 'Rynek'],
['Lemingowa Kawiarnia', 'Cafeteria', '/static/img/photo_1.jpg', '/static/img/photo_1.jpg', 'description', 'Oferta1', 'Promocja1' ], ['Lemingowa Kawiarnia', 'Cafeteria', '/static/img/photo_1.jpg', '/static/img/photo_1.jpg', 'description', 'Oferta1', 'Promocja1', 'Makowicka' ],
['Kafcia u Ewelinczaka', 'Cafeteria', '/static/img/photo_1.jpg', '/static/img/photo_1.jpg', 'description', 'Oferta2', 'Promocja2'], ['Kafcia u Ewelinczaka', 'Cafeteria', '/static/img/photo_1.jpg', '/static/img/photo_1.jpg', 'description', 'Oferta2', 'Promocja2', 'Rynek'],
] ]
print("Creating Places") print("Creating Places")
for place in places: for place in places:
print('Create {0}'.format(place[0])) print('Create {0}'.format(place[0]))
offer = Offer.objects.filter(name=place[5])[0] offer = Offer.objects.filter(name=place[5])[0]
promotion_set = PromotionSet.objects.filter(name=place[6])[0] 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) localization = Localization.objects.filter(road=place[7])[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, localization=localization)
new_place.save() new_place.save()
\ No newline at end of file
...@@ -27,6 +27,14 @@ class PromotionSet(models.Model): ...@@ -27,6 +27,14 @@ class PromotionSet(models.Model):
name = models.CharField(max_length=50) name = models.CharField(max_length=50)
promotions = models.ManyToManyField(Promotion, default='') promotions = models.ManyToManyField(Promotion, default='')
class Localization(models.Model):
latitude = models.CharField(max_length=50,)
longitude = models.CharField(max_length=50,)
city = models.CharField(max_length=50,)
road = models.CharField(max_length=50,)
road_number = models.CharField(max_length=50,)
class Place(models.Model): class Place(models.Model):
name = models.CharField(max_length=50, unique=True) name = models.CharField(max_length=50, unique=True)
type = models.CharField(max_length=50,) type = models.CharField(max_length=50,)
...@@ -35,3 +43,5 @@ class Place(models.Model): ...@@ -35,3 +43,5 @@ class Place(models.Model):
description = models.CharField(max_length=50) description = models.CharField(max_length=50)
offer = models.ForeignKey(Offer, null=True, blank=True) offer = models.ForeignKey(Offer, null=True, blank=True)
promotion = models.ForeignKey(PromotionSet, null=True, blank=True) promotion = models.ForeignKey(PromotionSet, null=True, blank=True)
localization = models.ForeignKey(Localization, null=True, blank=True)
...@@ -8,8 +8,10 @@ class ProductSerializer(serializers.HyperlinkedModelSerializer): ...@@ -8,8 +8,10 @@ class ProductSerializer(serializers.HyperlinkedModelSerializer):
model = Product model = Product
fields = ('url', 'id', 'name', 'description', 'price', 'img') fields = ('url', 'id', 'name', 'description', 'price', 'img')
class OfferSerializer(serializers.HyperlinkedModelSerializer): class OfferSerializer(serializers.HyperlinkedModelSerializer):
products = ProductSerializer(many=True) products = ProductSerializer(many=True)
class Meta: class Meta:
model = Offer model = Offer
fields = ('url', 'id', 'products') fields = ('url', 'id', 'products')
...@@ -23,14 +25,23 @@ class PromotionSerializer(serializers.HyperlinkedModelSerializer): ...@@ -23,14 +25,23 @@ class PromotionSerializer(serializers.HyperlinkedModelSerializer):
class PromotionSetSerializer(serializers.HyperlinkedModelSerializer): class PromotionSetSerializer(serializers.HyperlinkedModelSerializer):
promotions = PromotionSerializer(many=True) promotions = PromotionSerializer(many=True)
class Meta: class Meta:
model = Offer model = Offer
fields = ('url', 'id', 'promotions') fields = ('url', 'id', 'promotions')
class LocalizationSerializer(serializers.HyperlinkedModelSerializer):
class Meta:
model = Place
fields = ('url', 'id', 'latitude', 'longitude', 'city', 'road', 'road_number')
class PlaceSerializer(serializers.HyperlinkedModelSerializer): class PlaceSerializer(serializers.HyperlinkedModelSerializer):
offer = OfferSerializer() offer = OfferSerializer()
promotion = PromotionSetSerializer() promotion = PromotionSetSerializer()
localization = LocalizationSerializer()
class Meta: class Meta:
model = Place model = Place
fields = ('url', 'id', 'name', 'type', 'screen_img', 'logo_img', 'description', 'offer', 'promotion') fields = ('url', 'id', 'name', 'type', 'screen_img', 'logo_img', 'description', 'offer', 'promotion')
\ No newline at end of file
...@@ -2,9 +2,9 @@ from django.shortcuts import render ...@@ -2,9 +2,9 @@ from django.shortcuts import render
from rest_framework import viewsets, permissions from rest_framework import viewsets, permissions
from rest_framework.decorators import list_route from rest_framework.decorators import list_route
from App.loyaltyMe.models import Product, Offer, Promotion, Place, PromotionSet from App.loyaltyMe.models import Product, Offer, Promotion, Place, PromotionSet, Localization
from App.loyaltyMe.serializers import ProductSerializer, OfferSerializer, PromotionSerializer, PlaceSerializer, \ from App.loyaltyMe.serializers import ProductSerializer, OfferSerializer, PromotionSerializer, PlaceSerializer, \
PromotionSetSerializer PromotionSetSerializer, LocalizationSerializer
class ProductViewSet(viewsets.ModelViewSet): class ProductViewSet(viewsets.ModelViewSet):
...@@ -47,4 +47,13 @@ class PlaceViewSet(viewsets.ModelViewSet): ...@@ -47,4 +47,13 @@ class PlaceViewSet(viewsets.ModelViewSet):
""" """
queryset = Place.objects.all() queryset = Place.objects.all()
serializer_class = PlaceSerializer serializer_class = PlaceSerializer
permission_classes = (permissions.IsAuthenticatedOrReadOnly,)
class LocalizationViewSet(viewsets.ModelViewSet):
"""
API for articles
"""
queryset = Localization.objects.all()
serializer_class = LocalizationSerializer
permission_classes = (permissions.IsAuthenticatedOrReadOnly,) permission_classes = (permissions.IsAuthenticatedOrReadOnly,)
\ No newline at end of file
...@@ -13,5 +13,6 @@ class Command(BaseCommand): ...@@ -13,5 +13,6 @@ class Command(BaseCommand):
call_command('init_offers') call_command('init_offers')
call_command('init_promotions') call_command('init_promotions')
call_command('init_promotionsets') call_command('init_promotionsets')
call_command('init_localizations')
call_command('init_places') 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