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
cd7faaf8
Commit
cd7faaf8
authored
Sep 15, 2016
by
lizonr1
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add owners to models
parent
75f35872
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
32 additions
and
39 deletions
+32
-39
init_beacons.py
...nniczek/App/loyaltyMe/management/commands/init_beacons.py
+6
-3
init_places.py
...enniczek/App/loyaltyMe/management/commands/init_places.py
+11
-7
models.py
KawowyDzienniczek/App/loyaltyMe/models.py
+11
-11
serializers.py
KawowyDzienniczek/App/loyaltyMe/serializers.py
+2
-7
views.py
KawowyDzienniczek/App/loyaltyMe/views.py
+2
-11
No files found.
KawowyDzienniczek/App/loyaltyMe/management/commands/init_beacons.py
View file @
cd7faaf8
from
django.contrib.auth.models
import
User
from
App.loyaltyMe.models
import
Beacon
from
django.core.management.base
import
BaseCommand
...
...
@@ -8,12 +10,13 @@ class Command(BaseCommand):
def
handle
(
self
,
*
args
,
**
options
):
beacons
=
[
[
'f7826da6-4fa2-4e98-8024-bc5b71e0893e'
,
'hPUL'
,
'Bialy'
,
'2667'
,
'62313'
],
[
'74f1f28c-1cb7-11e5-9a21-1697f925ec7b'
,
'CeH3'
,
'Czarny'
,
'55059'
,
'55892'
],
[
'f7826da6-4fa2-4e98-8024-bc5b71e0893e'
,
'hPUL'
,
'Bialy'
,
'2667'
,
'62313'
,
'admin'
],
[
'74f1f28c-1cb7-11e5-9a21-1697f925ec7b'
,
'CeH3'
,
'Czarny'
,
'55059'
,
'55892'
,
'admin'
],
]
print
(
"Creating Beacons"
)
for
beacon
in
beacons
:
print
(
'Create {0}'
.
format
(
beacon
[
1
]))
user
=
User
.
objects
.
filter
(
username
=
beacon
[
5
])[
0
]
new_beacon
=
Beacon
.
objects
.
create
(
uuid
=
beacon
[
0
],
name
=
beacon
[
1
],
description
=
beacon
[
2
],
major
=
beacon
[
3
],
minor
=
beacon
[
4
])
minor
=
beacon
[
4
]
,
user
=
user
)
new_beacon
.
save
()
KawowyDzienniczek/App/loyaltyMe/management/commands/init_places.py
View file @
cd7faaf8
from
django.contrib.auth.models
import
User
from
django.core.management.base
import
BaseCommand
from
App.loyaltyMe.models
import
Place
,
Offer
,
Localization
,
Beacon
...
...
@@ -11,17 +12,17 @@ class Command(BaseCommand):
places
=
[
# ['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'
,
'hPUL
'
],
'Oferta1'
,
'
Wakacyjna Promocja'
,
'Makowicka'
,
'hPUL'
,
'admin
'
],
[
'Kafcia u Olczaka'
,
'Cafeteria'
,
'/static/img/photo_1.jpg'
,
'/static/img/photo_1.jpg'
,
'description'
,
'Oferta2'
,
'Promocja2'
,
'Makowicka'
,
'CeH3'
],
'Oferta2'
,
'Promocja2'
,
'Makowicka'
,
'CeH3'
,
'admin'
],
[
'Psia Kawiarnia'
,
'Cafeteria'
,
'/static/img/photo_1.jpg'
,
'/static/img/photo_1.jpg'
,
'description'
,
'Oferta1'
,
'
Promocja1'
,
'Rynek'
,
None
],
'Oferta1'
,
'
Wakacyjna Promocja'
,
'Rynek'
,
None
,
'admin'
],
[
'Kafcia u Iwczaka'
,
'Cafeteria'
,
'/static/img/photo_1.jpg'
,
'/static/img/photo_1.jpg'
,
'description'
,
'Oferta2'
,
'Promocja2'
,
'Rynek'
,
None
],
'Oferta2'
,
'Promocja2'
,
'Rynek'
,
None
,
'admin'
],
[
'Lemingowa Kawiarnia'
,
'Cafeteria'
,
'/static/img/photo_1.jpg'
,
'/static/img/photo_1.jpg'
,
'description'
,
'Oferta1'
,
'
Promocja1'
,
'Makowicka'
,
None
],
'Oferta1'
,
'
Wakacyjna Promocja'
,
'Makowicka'
,
None
,
'admin'
],
[
'Kafcia u Ewelinczaka'
,
'Cafeteria'
,
'/static/img/photo_1.jpg'
,
'/static/img/photo_1.jpg'
,
'description'
,
'Oferta2'
,
'Promocja2'
,
'Rynek'
,
None
],
'Oferta2'
,
'Promocja2'
,
'Rynek'
,
None
,
'admin'
],
]
print
(
"Creating Places"
)
for
place
in
places
:
...
...
@@ -33,7 +34,10 @@ class Command(BaseCommand):
beacon
=
Beacon
.
objects
.
filter
(
name
=
place
[
8
])[
0
]
else
:
beacon
=
None
owners
=
User
.
objects
.
filter
(
username
=
place
[
9
])
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
,
description
=
place
[
4
],
offer
=
offer
,
localization
=
localization
,
beacon
=
beacon
)
new_place
.
owners
=
owners
new_place
.
promotion
.
add
(
promotion_set
)
new_place
.
save
()
KawowyDzienniczek/App/loyaltyMe/models.py
View file @
cd7faaf8
...
...
@@ -22,8 +22,11 @@ class Localization(models.Model):
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
)
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
):
uuid
=
models
.
CharField
(
max_length
=
300
,
unique
=
True
)
...
...
@@ -31,6 +34,7 @@ class Beacon(models.Model):
minor
=
models
.
CharField
(
max_length
=
300
,
unique
=
True
)
name
=
models
.
CharField
(
max_length
=
300
)
description
=
models
.
CharField
(
max_length
=
300
,
null
=
True
)
user
=
models
.
ForeignKey
(
User
)
def
__str__
(
self
):
return
self
.
name
...
...
@@ -39,18 +43,14 @@ class Beacon(models.Model):
class
Place
(
models
.
Model
):
name
=
models
.
CharField
(
max_length
=
50
,
unique
=
True
)
type
=
models
.
CharField
(
max_length
=
50
,
)
screen_img
=
models
.
ImageField
()
logo_img
=
models
.
ImageField
()
description
=
models
.
CharField
(
max_length
=
50
)
screen_img
=
models
.
ImageField
(
blank
=
True
)
logo_img
=
models
.
ImageField
(
blank
=
True
)
description
=
models
.
CharField
(
max_length
=
50
,
blank
=
True
)
offer
=
models
.
ForeignKey
(
Offer
,
null
=
True
,
blank
=
True
)
promotion
=
models
.
ForeignKey
(
'promotion.PromotionSet'
,
null
=
True
,
blank
=
True
)
promotion
=
models
.
ManyToManyField
(
'promotion.PromotionSet'
,
blank
=
True
,
related_name
=
'place_promotion'
)
localization
=
models
.
ForeignKey
(
Localization
,
null
=
True
,
blank
=
True
)
beacon
=
models
.
ForeignKey
(
Beacon
,
null
=
True
,
blank
=
True
)
owners
=
models
.
ManyToManyField
(
User
,
related_name
=
'place_owners'
)
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 @
cd7faaf8
from
rest_framework
import
serializers
from
App.loyaltyMe.models
import
Product
,
Offer
,
Place
,
Localization
,
Beacon
,
UserPlace
from
App.loyaltyMe.models
import
Product
,
Offer
,
Place
,
Localization
,
Beacon
from
App.promotion.serializers
import
PromotionSetSerializer
...
...
@@ -40,9 +40,4 @@ class PlaceSerializer(serializers.HyperlinkedModelSerializer):
model
=
Place
fields
=
(
'url'
,
'id'
,
'name'
,
'type'
,
'screen_img'
,
'logo_img'
,
'description'
,
'offer'
,
'promotion'
,
'localization'
,
'beacon'
)
class
UserPlaceSerializer
(
serializers
.
HyperlinkedModelSerializer
):
class
Meta
:
model
=
UserPlace
fields
=
(
'url'
,
'id'
,
'user'
,
'place'
)
'beacon'
,
'owners'
)
KawowyDzienniczek/App/loyaltyMe/views.py
View file @
cd7faaf8
...
...
@@ -4,9 +4,9 @@ from rest_framework import viewsets, permissions
from
rest_framework.decorators
import
detail_route
from
rest_framework.response
import
Response
from
App.loyaltyMe.models
import
Product
,
Offer
,
Place
,
Localization
,
Beacon
,
UserPlace
from
App.loyaltyMe.models
import
Product
,
Offer
,
Place
,
Localization
,
Beacon
from
App.loyaltyMe.serializers
import
ProductSerializer
,
OfferSerializer
,
PlaceSerializer
,
\
LocalizationSerializer
,
BeaconSerializer
,
UserPlaceSerializer
LocalizationSerializer
,
BeaconSerializer
from
App.promotion.models
import
UserPromotion
...
...
@@ -47,12 +47,3 @@ class BeaconViewSet(viewsets.ModelViewSet):
queryset
=
Beacon
.
objects
.
all
()
serializer_class
=
BeaconSerializer
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
)
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