Commit 7e74eba8 authored by Rafal's avatar Rafal

Add beacon to place

parent bce19eaa
from App.loyaltyMe.models import Place, Offer, Promotion, PromotionSet, Localization from App.loyaltyMe.models import Place, Offer, Promotion, PromotionSet, Localization, Beacon
__author__ = 'Rafal' __author__ = 'Rafal'
from django.core.management.base import BaseCommand, CommandError from django.core.management.base import BaseCommand, CommandError
...@@ -9,12 +9,12 @@ class Command(BaseCommand): ...@@ -9,12 +9,12 @@ 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' , 'Makowicka'], ['Kocia Kawiarnia', 'Cafeteria', '/static/img/photo_1.jpg', '/static/img/photo_1.jpg', 'description', 'Oferta1', 'Promocja1' , 'Makowicka', 'hPUL'],
['Kafcia u Olczaka', 'Cafeteria', '/static/img/photo_1.jpg', '/static/img/photo_1.jpg', 'description', 'Oferta2', 'Promocja2' ,'Makowicka'], ['Kafcia u Olczaka', 'Cafeteria', '/static/img/photo_1.jpg', '/static/img/photo_1.jpg', 'description', 'Oferta2', 'Promocja2' ,'Makowicka', 'CeH3'],
['Psia Kawiarnia', 'Cafeteria', '/static/img/photo_1.jpg', '/static/img/photo_1.jpg', 'description', 'Oferta1', 'Promocja1', 'Rynek' ], ['Psia Kawiarnia', 'Cafeteria', '/static/img/photo_1.jpg', '/static/img/photo_1.jpg', 'description', 'Oferta1', 'Promocja1', 'Rynek', None],
['Kafcia u Iwczaka', 'Cafeteria', '/static/img/photo_1.jpg', '/static/img/photo_1.jpg', 'description', 'Oferta2', 'Promocja2', 'Rynek'], ['Kafcia u Iwczaka', 'Cafeteria', '/static/img/photo_1.jpg', '/static/img/photo_1.jpg', 'description', 'Oferta2', 'Promocja2', 'Rynek', None],
['Lemingowa Kawiarnia', 'Cafeteria', '/static/img/photo_1.jpg', '/static/img/photo_1.jpg', 'description', 'Oferta1', 'Promocja1', 'Makowicka' ], ['Lemingowa Kawiarnia', 'Cafeteria', '/static/img/photo_1.jpg', '/static/img/photo_1.jpg', 'description', 'Oferta1', 'Promocja1', 'Makowicka', None ],
['Kafcia u Ewelinczaka', 'Cafeteria', '/static/img/photo_1.jpg', '/static/img/photo_1.jpg', 'description', 'Oferta2', 'Promocja2', 'Rynek'], ['Kafcia u Ewelinczaka', 'Cafeteria', '/static/img/photo_1.jpg', '/static/img/photo_1.jpg', 'description', 'Oferta2', 'Promocja2', 'Rynek', None],
] ]
print("Creating Places") print("Creating Places")
for place in places: for place in places:
...@@ -22,5 +22,9 @@ class Command(BaseCommand): ...@@ -22,5 +22,9 @@ class Command(BaseCommand):
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]
localization = Localization.objects.filter(road=place[7])[0] 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) if place[8]:
beacon = Beacon.objects.filter(name=place[8])[0]
else:
beacon=None
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, beacon=beacon)
new_place.save() new_place.save()
\ No newline at end of file
...@@ -39,6 +39,15 @@ class Localization(models.Model): ...@@ -39,6 +39,15 @@ class Localization(models.Model):
road_number = models.CharField(max_length=50,) road_number = models.CharField(max_length=50,)
class Beacon(models.Model):
uuid = models.CharField(max_length=300, unique=True)
major = models.CharField(max_length=300, unique=True)
minor = models.CharField(max_length=300, unique=True)
name = models.CharField(max_length=300)
description = models.CharField(max_length=300, null=True)
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,)
...@@ -48,11 +57,5 @@ class Place(models.Model): ...@@ -48,11 +57,5 @@ class Place(models.Model):
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) localization = models.ForeignKey(Localization, null=True, blank=True)
beacon = models.ForeignKey(Beacon, null=True, blank=True)
class Beacon(models.Model):
uuid = models.CharField(max_length=300, unique=True)
major = models.CharField(max_length=300, unique=True)
minor = models.CharField(max_length=300, unique=True)
name = models.CharField(max_length=300)
description = models.CharField(max_length=300, null=True)
...@@ -41,6 +41,7 @@ class PlaceSerializer(serializers.HyperlinkedModelSerializer): ...@@ -41,6 +41,7 @@ class PlaceSerializer(serializers.HyperlinkedModelSerializer):
offer = OfferSerializer() offer = OfferSerializer()
promotion = PromotionSetSerializer() promotion = PromotionSetSerializer()
localization = LocalizationSerializer() localization = LocalizationSerializer()
beacon = BeaconSerializer()
class Meta: class Meta:
model = Place model = Place
......
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