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
15ef41dc
Commit
15ef41dc
authored
Jul 06, 2016
by
lizonr1
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add promotionssets and new data
parent
fb50e22d
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
67 additions
and
11 deletions
+67
-11
init_places.py
...enniczek/App/loyaltyMe/management/commands/init_places.py
+9
-7
init_promotionsets.py
...k/App/loyaltyMe/management/commands/init_promotionsets.py
+26
-0
models.py
KawowyDzienniczek/App/loyaltyMe/models.py
+4
-1
serializers.py
KawowyDzienniczek/App/loyaltyMe/serializers.py
+13
-1
views.py
KawowyDzienniczek/App/loyaltyMe/views.py
+13
-2
init.py
KawowyDzienniczek/App/user/management/commands/init.py
+1
-0
urls.py
KawowyDzienniczek/KawowyDzienniczek/urls.py
+1
-0
No files found.
KawowyDzienniczek/App/loyaltyMe/management/commands/init_places.py
View file @
15ef41dc
from
App.loyaltyMe.models
import
Place
,
Offer
,
Promotion
from
App.loyaltyMe.models
import
Place
,
Offer
,
Promotion
,
PromotionSet
__author__
=
'Rafal'
__author__
=
'Rafal'
from
django.core.management.base
import
BaseCommand
,
CommandError
from
django.core.management.base
import
BaseCommand
,
CommandError
...
@@ -9,15 +9,17 @@ class Command(BaseCommand):
...
@@ -9,15 +9,17 @@ 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/media/img/photo_1.jpg'
,
'/static/media/img/photo_1.jpg'
,
'description'
,
'Oferta1'
,
[
'10
%
'
,
'20
%
'
]],
[
'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'
,
[
'20
%
'
,
'50
%
'
]],
[
'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"
)
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
]
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_set
=
PromotionSet
.
objects
.
filter
(
name
=
place
[
6
])[
0
]
for
promotion
in
place
[
6
]:
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
)
prom_obj
=
Promotion
.
objects
.
filter
(
name
=
promotion
)[
0
]
new_place
.
promotions
.
add
(
prom_obj
)
new_place
.
save
()
new_place
.
save
()
\ No newline at end of file
KawowyDzienniczek/App/loyaltyMe/management/commands/init_promotionsets.py
0 → 100644
View file @
15ef41dc
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
KawowyDzienniczek/App/loyaltyMe/models.py
View file @
15ef41dc
...
@@ -23,6 +23,9 @@ class Promotion(models.Model):
...
@@ -23,6 +23,9 @@ class Promotion(models.Model):
img
=
models
.
ImageField
()
img
=
models
.
ImageField
()
status
=
models
.
CharField
(
max_length
=
50
)
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
):
class
Place
(
models
.
Model
):
name
=
models
.
CharField
(
max_length
=
50
,
unique
=
True
)
name
=
models
.
CharField
(
max_length
=
50
,
unique
=
True
)
...
@@ -31,4 +34,4 @@ class Place(models.Model):
...
@@ -31,4 +34,4 @@ class Place(models.Model):
logo_img
=
models
.
ImageField
()
logo_img
=
models
.
ImageField
()
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
s
=
models
.
ManyToManyField
(
Promotion
,
default
=
''
)
promotion
=
models
.
ForeignKey
(
PromotionSet
,
null
=
True
,
blank
=
True
)
KawowyDzienniczek/App/loyaltyMe/serializers.py
View file @
15ef41dc
...
@@ -9,16 +9,28 @@ class ProductSerializer(serializers.HyperlinkedModelSerializer):
...
@@ -9,16 +9,28 @@ class ProductSerializer(serializers.HyperlinkedModelSerializer):
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
)
class
Meta
:
class
Meta
:
model
=
Offer
model
=
Offer
fields
=
(
'url'
,
'id'
,
'products'
)
fields
=
(
'url'
,
'id'
,
'products'
)
class
PromotionSerializer
(
serializers
.
HyperlinkedModelSerializer
):
class
PromotionSerializer
(
serializers
.
HyperlinkedModelSerializer
):
class
Meta
:
class
Meta
:
model
=
Promotion
model
=
Promotion
fields
=
(
'url'
,
'id'
,
'name'
,
'description'
,
'code'
,
'img'
,
'status'
)
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
):
class
PlaceSerializer
(
serializers
.
HyperlinkedModelSerializer
):
offer
=
OfferSerializer
()
promotion
=
PromotionSetSerializer
()
class
Meta
:
class
Meta
:
model
=
Place
model
=
Place
fields
=
(
'url'
,
'id'
,
'name'
,
'type'
,
'screen_img'
,
'logo_img'
,
'description'
,
'offer'
,
'promotions'
)
fields
=
(
'url'
,
'id'
,
'name'
,
'type'
,
'screen_img'
,
'logo_img'
,
'description'
,
'offer'
,
'promotion'
)
\ No newline at end of file
\ No newline at end of file
KawowyDzienniczek/App/loyaltyMe/views.py
View file @
15ef41dc
...
@@ -2,8 +2,9 @@ from django.shortcuts import render
...
@@ -2,8 +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
from
App.loyaltyMe.models
import
Product
,
Offer
,
Promotion
,
Place
,
PromotionSet
from
App.loyaltyMe.serializers
import
ProductSerializer
,
OfferSerializer
,
PromotionSerializer
,
PlaceSerializer
from
App.loyaltyMe.serializers
import
ProductSerializer
,
OfferSerializer
,
PromotionSerializer
,
PlaceSerializer
,
\
PromotionSetSerializer
class
ProductViewSet
(
viewsets
.
ModelViewSet
):
class
ProductViewSet
(
viewsets
.
ModelViewSet
):
...
@@ -30,6 +31,16 @@ class PromotionViewSet(viewsets.ModelViewSet):
...
@@ -30,6 +31,16 @@ class PromotionViewSet(viewsets.ModelViewSet):
serializer_class
=
PromotionSerializer
serializer_class
=
PromotionSerializer
permission_classes
=
(
permissions
.
IsAuthenticatedOrReadOnly
,)
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
):
class
PlaceViewSet
(
viewsets
.
ModelViewSet
):
"""
"""
API for articles
API for articles
...
...
KawowyDzienniczek/App/user/management/commands/init.py
View file @
15ef41dc
...
@@ -11,5 +11,6 @@ class Command(BaseCommand):
...
@@ -11,5 +11,6 @@ class Command(BaseCommand):
call_command
(
'init_products'
)
call_command
(
'init_products'
)
call_command
(
'init_offers'
)
call_command
(
'init_offers'
)
call_command
(
'init_promotions'
)
call_command
(
'init_promotions'
)
call_command
(
'init_promotionsets'
)
call_command
(
'init_places'
)
call_command
(
'init_places'
)
KawowyDzienniczek/KawowyDzienniczek/urls.py
View file @
15ef41dc
...
@@ -28,6 +28,7 @@ router.register(r'user', user_views.UserViewSet)
...
@@ -28,6 +28,7 @@ router.register(r'user', user_views.UserViewSet)
router
.
register
(
r'products'
,
loyalty_views
.
ProductViewSet
)
router
.
register
(
r'products'
,
loyalty_views
.
ProductViewSet
)
router
.
register
(
r'offerts'
,
loyalty_views
.
OfferViewSet
)
router
.
register
(
r'offerts'
,
loyalty_views
.
OfferViewSet
)
router
.
register
(
r'promotions'
,
loyalty_views
.
PromotionViewSet
)
router
.
register
(
r'promotions'
,
loyalty_views
.
PromotionViewSet
)
router
.
register
(
r'promotion_set'
,
loyalty_views
.
PromotionSetViewSet
)
router
.
register
(
r'places'
,
loyalty_views
.
PlaceViewSet
)
router
.
register
(
r'places'
,
loyalty_views
.
PlaceViewSet
)
urlpatterns
=
[
urlpatterns
=
[
...
...
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