Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

all tests passing #3

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions ecommerce/api/serializers.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
from rest_framework import serializers
from products.models import Product

from products.models import Product, Category

class ProductModelSerializer(serializers.ModelSerializer):

class ProductSerializer():
# YOUR CODE HERE
pass
class Meta:
model = Product # model to serialize into JSON
fields = ['id', 'name', 'sku', 'category', 'description', 'price', 'created', 'featured'] # can be tuple
12 changes: 6 additions & 6 deletions ecommerce/api/urls.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
from django.contrib import admin
from django.urls import path, include

from rest_framework.routers import DefaultRouter

from api import views


router = DefaultRouter()

# Register the 'products' urls in the router
router.register('...')
router.register('products', views.ProductViewSet, base_name='products') # 'products' first argument is path('products/', ...)... New urls are generated off this
# base_name='product' is like name='product' in a path()

urlpatterns = [url for url in router.urls]

urlpatterns = []
urlpatterns += router.urls
# OR do the following from an empty list:
# urlpatterns += router.urls
8 changes: 6 additions & 2 deletions ecommerce/api/views.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
from rest_framework import viewsets
from products.models import Product
from api.serializers import ProductSerializer
from api.serializers import ProductModelSerializer


# YOUR VIEWS HERE
class ProductViewSet(viewsets.ModelViewSet): # No need to make .put(), .post() etc due to this ModelViewSet
serializer_class = ProductModelSerializer # Make serializer to turn a Model into a JSON object...
queryset = Product.objects.all() # DRF knows to .get() a detail view, etc... Do .all() as standard
# But, you can .filter() this etc.
Binary file modified ecommerce/db.sqlite3
Binary file not shown.