Skip to content
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
26 changes: 26 additions & 0 deletions commerce/controllers.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,29 @@
from django.db import router
from django.http.response import JsonResponse
from django.shortcuts import render
from ninja.router import Router
from commerce.models import Address, Product
from ninja import NinjaAPI
from django.forms.models import model_to_dict
from django.http import JsonResponse




# Create your views here.
api= NinjaAPI()

product_c= Router()
address_c = Router()

@product_c.get('/')
def all_product(request):
#return JsonResponse({"product", list(Product.objects.all())})
data= Product.objects.all().values()
return JsonResponse({"product": list(data)})

@address_c.get('/address')
def all_add(request):
ddata= Address.objects.all().values()
return JsonResponse({"address": list(ddata)})

2 changes: 1 addition & 1 deletion commerce/migrations/0001_initial.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

class Migration(migrations.Migration):

initial = True
initial = True # means first migration

dependencies = [
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
Expand Down
2 changes: 2 additions & 0 deletions commerce/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,3 +210,5 @@ class Address(Entity):

def __str__(self):
return f'{self.user.first_name} - {self.address1} - {self.address2} - {self.phone}'


1 change: 1 addition & 0 deletions commerce/tests.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from django.test import TestCase
from models import Product

# Create your tests here.
12 changes: 12 additions & 0 deletions config/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,19 @@
"""
from django.contrib import admin
from django.urls import path
from django.urls import path, include
from ninja import NinjaAPI
from commerce.controllers import product_c, address_c
import ninja

api= NinjaAPI()

api.add_router('/', product_c)
api.add_router('/', address_c)

urlpatterns = [

path('admin/', admin.site.urls),
path('api/', api.urls)

]
1 change: 1 addition & 0 deletions manage.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import sys



def main():
"""Run administrative tasks."""
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'config.settings')
Expand Down