File size: 783 Bytes
a61be63
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
from django.shortcuts import render
from .models import Diamond, BrandProduct
from fastapi import FastAPI

app = FastAPI()

@app.get("/diamonds/")
def get_diamonds():
    diamonds = Diamond.objects.all()
    return {"diamonds": [{"id": d.id, "carat": d.carat, "cut": d.cut, "color": d.color, "clarity": d.clarity, "depth": d.depth} for d in diamonds]}

@app.get("/brand_products/")
def get_brand_products():
    brand_products = BrandProduct.objects.all()
    return {"brand_products": [{"id": bp.id, "brand_name": bp.brand_name, "model_name": bp.model_name, "type_number": bp.type_number, "purchase_store": bp.purchase_store, "purchase_date": bp.purchase_date, "purchase_price": bp.purchase_price, "accessories": bp.accessories, "condition": bp.condition} for bp in brand_products]}