Commit 8cb82fea authored by lizonr1's avatar lizonr1

Add models with serializers and views:

Product, Offer, Place,
parent bb09d43d
from django.db import models
# Create your models here.
class Product(models.Model):
name = models.CharField(max_length=50)
description = models.CharField(max_length=50)
price = models.CharField(max_length=50)
img = models.ImageField()
class Offer(models.Model):
products = models.ManyToManyField(Product)
class Promotion(models.Model):
name = models.CharField(max_length=50)
description = models.CharField(max_length=50)
code = models.CharField(max_length=50)
img = models.ImageField()
status = models.CharField(max_length=50)
class Place(models.Model):
name = models.CharField(max_length=50, unique=True)
type = models.CharField(max_length=50, unique=True)
screen_img = models.ImageField()
logo_img = models.ImageField()
description = models.CharField(max_length=50)
offer = models.ForeignKey(Offer)
promotions = models.ForeignKey(Promotion)
from rest_framework import serializers
from App.loyaltyMe.models import Product, Offer, Promotion, Place
class ProductSerializer(serializers.HyperlinkedModelSerializer):
class Meta:
model = Product
fields = ('url', 'id', 'name', 'description', 'price', 'img')
class OfferSerializer(serializers.HyperlinkedModelSerializer):
class Meta:
model = Offer
fields = ('url', 'id', 'products')
class PromotionSerializer(serializers.HyperlinkedModelSerializer):
class Meta:
model = Promotion
fields = ('url', 'id', 'name', 'description', 'code', 'img', 'status')
class PlaceSerializer(serializers.HyperlinkedModelSerializer):
class Meta:
model = Place
fields = ('url', 'id', 'name', 'type', 'screen_img', 'logo_img', 'description', 'offer', 'promotions')
\ No newline at end of file
...@@ -39,7 +39,8 @@ INSTALLED_APPS = [ ...@@ -39,7 +39,8 @@ INSTALLED_APPS = [
'rest_framework', 'rest_framework',
'rest_framework.authtoken', 'rest_framework.authtoken',
'App.user', 'App.user',
'App.page' 'App.page',
'App.loyaltyMe',
] ]
REST_FRAMEWORK = { REST_FRAMEWORK = {
...@@ -145,4 +146,6 @@ APPEND_SLASH = False ...@@ -145,4 +146,6 @@ APPEND_SLASH = False
PROJECT_DIR = os.path.abspath(os.path.dirname(__file__)) PROJECT_DIR = os.path.abspath(os.path.dirname(__file__))
PROJECT_ROOT = os.path.dirname(os.path.abspath(__file__)) PROJECT_ROOT = os.path.dirname(os.path.abspath(__file__))
STATIC_ROOT = os.path.join(PROJECT_DIR, 'static') STATIC_ROOT = os.path.join(PROJECT_DIR, 'static')
MEDIA_ROOT = os.path.join(PROJECT_DIR, 'media') MEDIA_ROOT = os.path.join(PROJECT_DIR, 'media')
\ No newline at end of file
APPEND_SLASH = True
\ No newline at end of file
...@@ -19,14 +19,16 @@ from django.contrib import admin ...@@ -19,14 +19,16 @@ from django.contrib import admin
from rest_framework import routers from rest_framework import routers
from App.page.views import coming_soon_page from App.page.views import coming_soon_page
from App.user import views as user_views
from rest_framework.authtoken import views as token_view
from KawowyDzienniczek import settings
from App.user import views as user_views from App.user import views as user_views
from App.loyaltyMe import views as loyalty_views
router = routers.DefaultRouter() router = routers.DefaultRouter()
router.register(r'user', user_views.UserViewSet) router.register(r'user', user_views.UserViewSet)
router.register(r'products', loyalty_views.ProductViewSet)
router.register(r'offerts', loyalty_views.OfferViewSet)
router.register(r'promotions', loyalty_views.PromotionViewSet)
router.register(r'places', loyalty_views.PlaceViewSet)
urlpatterns = [ urlpatterns = [
url(r'^api/', include(router.urls)), url(r'^api/', include(router.urls)),
......
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