From f789b65d653c117cf7a6f30d5a339e14a3d89a52 Mon Sep 17 00:00:00 2001 From: Janna Tammar Al-Ward Date: Tue, 9 Nov 2021 00:24:02 +0300 Subject: [PATCH] first commit --- .idea/03-commerce.iml | 2 +- .idea/misc.xml | 2 +- commerce/admin.py | 3 +-- commerce/controllers.py | 14 ++++++++++++++ config/urls.py | 7 +++++++ 5 files changed, 24 insertions(+), 4 deletions(-) diff --git a/.idea/03-commerce.iml b/.idea/03-commerce.iml index f602895..3f948e3 100644 --- a/.idea/03-commerce.iml +++ b/.idea/03-commerce.iml @@ -16,7 +16,7 @@ - + diff --git a/.idea/misc.xml b/.idea/misc.xml index 0c95c56..296aa57 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -1,4 +1,4 @@ - + \ No newline at end of file diff --git a/commerce/admin.py b/commerce/admin.py index ed9f6cc..0c87222 100644 --- a/commerce/admin.py +++ b/commerce/admin.py @@ -1,6 +1,5 @@ from django.contrib import admin - -from commerce.models import Product, Order, Item, Address, OrderStatus, ProductImage, City, Category +from commerce.models import * admin.site.register(Product) admin.site.register(Order) diff --git a/commerce/controllers.py b/commerce/controllers.py index 91ea44a..73b486d 100644 --- a/commerce/controllers.py +++ b/commerce/controllers.py @@ -1,3 +1,17 @@ from django.shortcuts import render +from ninja import Router +from commerce.models import * # Create your views here. +product_control = Router() +address_control = Router() + + +@product_control.get('') +def list_products(request): + return list(Product.object.all().values()) + + +@address_control.get('') +def list_addresses(request): + return list(Product.object.all().values()) diff --git a/config/urls.py b/config/urls.py index d52e577..b381d2a 100644 --- a/config/urls.py +++ b/config/urls.py @@ -15,7 +15,14 @@ """ from django.contrib import admin from django.urls import path +from ninja import NinjaAPI +from commerce.controllers import product_control, address_control + +api = NinjaAPI() +api.add_router('products/', product_control) +api.add_router('addresses/', address_control) urlpatterns = [ path('admin/', admin.site.urls), + path('api/', api.urls) ]