Commit 3294d867 authored by lizonr1's avatar lizonr1

Add user_place

parent 39583281
from django.contrib.auth.models import User
from django.db import models from django.db import models
# Create your models here.
class Product(models.Model): class Product(models.Model):
name = models.CharField(max_length=50) name = models.CharField(max_length=50)
description = models.CharField(max_length=50) description = models.CharField(max_length=50)
...@@ -24,6 +21,9 @@ class Localization(models.Model): ...@@ -24,6 +21,9 @@ class Localization(models.Model):
road = models.CharField(max_length=50, ) road = models.CharField(max_length=50, )
road_number = models.CharField(max_length=50, ) road_number = models.CharField(max_length=50, )
def __str__(self):
return "{city}, {road} {road_number}, {latitude}:{longitude}".format(city=self.city, road=self.road, road_number=self.road_number,
latitude=self.latitude, longitude=self.longitude)
class Beacon(models.Model): class Beacon(models.Model):
uuid = models.CharField(max_length=300, unique=True) uuid = models.CharField(max_length=300, unique=True)
...@@ -32,6 +32,9 @@ class Beacon(models.Model): ...@@ -32,6 +32,9 @@ class Beacon(models.Model):
name = models.CharField(max_length=300) name = models.CharField(max_length=300)
description = models.CharField(max_length=300, null=True) description = models.CharField(max_length=300, null=True)
def __str__(self):
return self.name
class Place(models.Model): class Place(models.Model):
name = models.CharField(max_length=50, unique=True) name = models.CharField(max_length=50, unique=True)
...@@ -43,3 +46,11 @@ class Place(models.Model): ...@@ -43,3 +46,11 @@ class Place(models.Model):
promotion = models.ForeignKey('promotion.PromotionSet', null=True, blank=True) promotion = models.ForeignKey('promotion.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) beacon = models.ForeignKey(Beacon, null=True, blank=True)
def __str__(self):
return self.name
class UserPlace(models.Model):
place = models.ForeignKey(Place, related_name='userplace_place')
user = models.ForeignKey(User, related_name='userplace_user')
from rest_framework import serializers from rest_framework import serializers
from App.loyaltyMe.models import Product, Offer, Place, Localization, Beacon from App.loyaltyMe.models import Product, Offer, Place, Localization, Beacon, UserPlace
from App.promotion.serializers import PromotionSetSerializer from App.promotion.serializers import PromotionSetSerializer
...@@ -42,3 +42,7 @@ class PlaceSerializer(serializers.HyperlinkedModelSerializer): ...@@ -42,3 +42,7 @@ class PlaceSerializer(serializers.HyperlinkedModelSerializer):
'url', 'id', 'name', 'type', 'screen_img', 'logo_img', 'description', 'offer', 'promotion', 'localization', 'url', 'id', 'name', 'type', 'screen_img', 'logo_img', 'description', 'offer', 'promotion', 'localization',
'beacon') 'beacon')
class UserPlaceSerializer(serializers.HyperlinkedModelSerializer):
class Meta:
model = UserPlace
fields = ('url', 'id', 'user', 'place')
from django.test import TestCase
from rest_framework.test import APIRequestFactory
class TaskTestCase(TestCase):
def setUp(self):
pass
def test_refresh(self):
factory = APIRequestFactory()
request = factory.get('/places/1/refresh', format='json')
print(request)
\ No newline at end of file
...@@ -4,9 +4,9 @@ from rest_framework import viewsets, permissions ...@@ -4,9 +4,9 @@ from rest_framework import viewsets, permissions
from rest_framework.decorators import detail_route from rest_framework.decorators import detail_route
from rest_framework.response import Response from rest_framework.response import Response
from App.loyaltyMe.models import Product, Offer, Place, Localization, Beacon from App.loyaltyMe.models import Product, Offer, Place, Localization, Beacon, UserPlace
from App.loyaltyMe.serializers import ProductSerializer, OfferSerializer, PlaceSerializer, \ from App.loyaltyMe.serializers import ProductSerializer, OfferSerializer, PlaceSerializer, \
LocalizationSerializer, BeaconSerializer LocalizationSerializer, BeaconSerializer, UserPlaceSerializer
from App.promotion.models import UserPromotion from App.promotion.models import UserPromotion
...@@ -47,3 +47,12 @@ class BeaconViewSet(viewsets.ModelViewSet): ...@@ -47,3 +47,12 @@ class BeaconViewSet(viewsets.ModelViewSet):
queryset = Beacon.objects.all() queryset = Beacon.objects.all()
serializer_class = BeaconSerializer serializer_class = BeaconSerializer
permission_classes = (permissions.IsAuthenticatedOrReadOnly,) permission_classes = (permissions.IsAuthenticatedOrReadOnly,)
class UserPlaceViewSet(viewsets.ModelViewSet):
queryset = UserPlace.objects.all()
serializer_class = UserPlaceSerializer
permission_classes = (permissions.IsAuthenticatedOrReadOnly,)
def get_queryset(self):
user = self.request.user
return UserPlace.objects.filter(user=user)
...@@ -23,7 +23,7 @@ class Command(BaseCommand): ...@@ -23,7 +23,7 @@ class Command(BaseCommand):
['Klaudia', 'Kocia Kawiarnia', '10%', 'US', 'abcd', 'Bądź u nas 10 godzin'], ['Klaudia', 'Kocia Kawiarnia', '10%', 'US', 'abcd', 'Bądź u nas 10 godzin'],
['Klaudia', 'Kafcia u Olczaka', '20%', 'AC', 'abcd', 'Przyjdz 10 razy'], ['Klaudia', 'Kafcia u Olczaka', '20%', 'AC', 'abcd', 'Przyjdz 10 razy'],
['Antek', 'Kafcia u Olczaka', '50%', 'AC', 'abcd', 'Bądź u nas 10 godzin'], ['Antek', 'Kafcia u Olczaka', '50%', 'AC', 'abcd', 'Bądź u nas 10 godzin'],
['admin', 'Kafcia u Olczaka', '10%', 'AC', 'abcd', 'Przyjdz 10 razy'], ['admin', 'Kafcia u Olczaka', '20%', 'AC', 'abcd', 'Przyjdz 10 razy'],
] ]
print("Creating UserPromotions") print("Creating UserPromotions")
for user_promotion in user_promotions: for user_promotion in user_promotions:
......
...@@ -49,10 +49,16 @@ class Promotion(models.Model): ...@@ -49,10 +49,16 @@ class Promotion(models.Model):
start_date = models.DateField(null=True) start_date = models.DateField(null=True)
end_date = models.DateField(null=True) end_date = models.DateField(null=True)
def __str__(self):
return self.name
class PromotionSet(models.Model): class PromotionSet(models.Model):
name = models.CharField(max_length=20) name = models.CharField(max_length=20)
promotions = models.ManyToManyField(Promotion, default='') promotions = models.ManyToManyField('promotion.Promotion', default='')
def __str__(self):
return self.name
class UserTask(models.Model): class UserTask(models.Model):
......
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