diff --git a/www/web/warppay/models.py b/www/web/warppay/models.py index 4f75293b767b54e8f94f91e0787ce9dd57b12af7..17ad85cda0abae03dcad676efe64e4d6d4ed5d93 100644 --- a/www/web/warppay/models.py +++ b/www/web/warppay/models.py @@ -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) diff --git a/www/web/warppay/urls.py b/www/web/warppay/urls.py index f576626ffa577a2c650aada5d0a97d5cb0e16683..626d2384e6a353a7723a2f8caa6c97c5112b1d15 100644 --- a/www/web/warppay/urls.py +++ b/www/web/warppay/urls.py @@ -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), diff --git a/www/web/warppay/views.py b/www/web/warppay/views.py index e3365b2c5dd29a9128c249718f87d91dbdccf945..b7a1da50fef959856ccaeeada75b906c48da8884 100644 --- a/www/web/warppay/views.py +++ b/www/web/warppay/views.py @@ -1,7 +1,7 @@ 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,))