Skip to content
Snippets Groups Projects
Commit f67f8a0b authored by Christian Dresen's avatar Christian Dresen
Browse files

[WarpPay] Added API Path for Categories

parent a816c30e
No related branches found
No related tags found
No related merge requests found
......@@ -9,6 +9,10 @@ class ProductCategory(models.Model):
def __str__(self):
return self.name
class ProductCategorySerializer(serializers.ModelSerializer):
class Meta:
model = ProductCategory
fields = ['id', 'name']
class Product(models.Model):
name = models.CharField(max_length=100, null=True)
......
......@@ -6,6 +6,7 @@ urlpatterns = [
url(r'^api/users/$', views.user_list),
url(r'^api/users/(?P<user_id>\w+)/$', views.user_list),
url(r'^api/products/$', views.product_list),
url(r'^api/categories/$', views.category_list),
url(r'^api/gen_token/$', views.gen_token),
url(r'^api/transaction/(?P<user_id>\w+)/$', views.transaction),
......
from django.db import IntegrityError
from django.core.exceptions import ObjectDoesNotExist
from warpauth.models import LdapUser
from warppay.models import UserCredit, UserCreditSerializer, Product, ProductSerializer, Transaction
from warppay.models import UserCredit, UserCreditSerializer, Product, ProductSerializer, ProductCategory, ProductCategorySerializer, Transaction
from rest_framework.decorators import api_view
from rest_framework.response import Response
from rest_framework.authentication import TokenAuthentication
......@@ -13,6 +13,18 @@ from rest_framework import status
# logging.getLogger('main').info(token.key)
@api_view(['GET', 'PUT'])
#@authentication_classes((TokenAuthentication,))
#@permission_classes((IsAuthenticated,))
def category_list(request):
if request.method == 'GET':
products = ProductCategory.objects.all()
serializer = ProductCategorySerializer(products,context={'request': request}, many=True)
return Response(serializer.data)
return Response()
@api_view(['GET', 'PUT'])
#@authentication_classes((TokenAuthentication,))
#@permission_classes((IsAuthenticated,))
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment