Start using rest framework
This commit is contained in:
1 parent
de85988039
commit
3b7980ffe9
5 files changed
+24
-1
No files matched your search
@@ -87,6 +87,7 @@ INSTALLED_APPS = (
|
|||||||
'bootstrapform',
|
'bootstrapform',
|
||||||
'compressor',
|
'compressor',
|
||||||
'django_extensions',
|
'django_extensions',
|
||||||
|
'rest_framework',
|
||||||
)
|
)
|
||||||
LOCAL_APPS = (
|
LOCAL_APPS = (
|
||||||
'main',
|
'main',
|
||||||
|
|||||||
Whitespace-only changes.
@@ -0,0 +1,7 @@
|
|||||||
|
from main.models import Product
|
||||||
|
from rest_framework.serializers import ModelSerializer
|
||||||
|
|
||||||
|
|
||||||
|
class ProductSerializer(ModelSerializer):
|
||||||
|
class Meta:
|
||||||
|
model = Product
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
from main.api.serializers import ProductSerializer
|
||||||
|
from main.models import Product
|
||||||
|
from rest_framework.viewsets import ModelViewSet
|
||||||
|
|
||||||
|
|
||||||
|
class ProductViewSet(ModelViewSet):
|
||||||
|
# TODO: auth
|
||||||
|
serializer_class = ProductSerializer
|
||||||
|
queryset = Product.objects.all()
|
||||||
+7
-1
@@ -1,10 +1,11 @@
|
|||||||
from django.conf.urls import url
|
from django.conf.urls import url
|
||||||
|
from main.api.views import ProductViewSet
|
||||||
from main.views.stats import stats_list, stats_orders, stats_orders_hourly, stats_products_realtime, stats_products, \
|
from main.views.stats import stats_list, stats_orders, stats_orders_hourly, stats_products_realtime, stats_products, \
|
||||||
stats_products_per_user, products_json
|
stats_products_per_user, products_json
|
||||||
from main.views.general import register, deposit, log
|
from main.views.general import register, deposit, log
|
||||||
from main.views.reports import inventory, inventory_add, report
|
from main.views.reports import inventory, inventory_add, report
|
||||||
from main.views.users import create_user, profile
|
from main.views.users import create_user, profile
|
||||||
|
from rest_framework.routers import DefaultRouter
|
||||||
|
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
url(r'^$', register, name='home'),
|
url(r'^$', register, name='home'),
|
||||||
@@ -31,3 +32,8 @@ urlpatterns = [
|
|||||||
url(r'^inventory/add/$', inventory_add, name='inventory-add'),
|
url(r'^inventory/add/$', inventory_add, name='inventory-add'),
|
||||||
url(r'^report$', report, name='report'),
|
url(r'^report$', report, name='report'),
|
||||||
]
|
]
|
||||||
|
|
||||||
|
# API
|
||||||
|
router = DefaultRouter()
|
||||||
|
router.register(r'api/products', ProductViewSet)
|
||||||
|
urlpatterns += router.urls
|
||||||
Reference in new issue
Block a user