Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
K
KawowyDzienniczek
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Rafal
KawowyDzienniczek
Commits
3294d867
Commit
3294d867
authored
Aug 11, 2016
by
lizonr1
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add user_place
parent
39583281
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
51 additions
and
9 deletions
+51
-9
models.py
KawowyDzienniczek/App/loyaltyMe/models.py
+15
-4
serializers.py
KawowyDzienniczek/App/loyaltyMe/serializers.py
+5
-1
test_views.py
KawowyDzienniczek/App/loyaltyMe/test_views.py
+12
-0
views.py
KawowyDzienniczek/App/loyaltyMe/views.py
+11
-2
init_userpromotions.py
.../App/promotion/management/commands/init_userpromotions.py
+1
-1
models.py
KawowyDzienniczek/App/promotion/models.py
+7
-1
No files found.
KawowyDzienniczek/App/loyaltyMe/models.py
View file @
3294d867
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'
)
KawowyDzienniczek/App/loyaltyMe/serializers.py
View file @
3294d867
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'
)
KawowyDzienniczek/App/loyaltyMe/test_views.py
View file @
3294d867
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
KawowyDzienniczek/App/loyaltyMe/views.py
View file @
3294d867
...
@@ -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
)
KawowyDzienniczek/App/promotion/management/commands/init_userpromotions.py
View file @
3294d867
...
@@ -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'
,
'
1
0
%
'
,
'AC'
,
'abcd'
,
'Przyjdz 10 razy'
],
[
'admin'
,
'Kafcia u Olczaka'
,
'
2
0
%
'
,
'AC'
,
'abcd'
,
'Przyjdz 10 razy'
],
]
]
print
(
"Creating UserPromotions"
)
print
(
"Creating UserPromotions"
)
for
user_promotion
in
user_promotions
:
for
user_promotion
in
user_promotions
:
...
...
KawowyDzienniczek/App/promotion/models.py
View file @
3294d867
...
@@ -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
):
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment