djangorestframework>=3.12.0 djangorestframework-simplejwt>=4.7.2
ID | Name | Price | Image |
---|---|---|---|
1 | Hand Blender | 500 | |
2 | Micro-wave | 2000 |
id | quantity | product_id | user_id | status |
---|---|---|---|---|
1 | 2 | 2 | 1 | 0 |
from django.contrib.auth.models import User
from django.db import models
class Product(models.Model):
name = models.CharField(max_length=255)
price = models.DecimalField(max_digits=10, decimal_places=2)
image = models.CharField(max_length=255, null=True, blank=True)
def __str__(self):
return self.name
class CartItem(models.Model):
user = models.ForeignKey(User, on_delete=models.CASCADE)
product = models.ForeignKey(Product, on_delete=models.CASCADE)
quantity = models.PositiveIntegerField(default=1)
status = models.IntegerField(default=0) # 0 for not checked out, 1 for checked out
@property
def total_price(self):
return self.quantity * self.product.price
def __str__(self):
return f"{self.quantity} x {self.product.name}"
curl -X GET http://127.0.0.1:8001/api/v1/products/
=> curl -X POST \
http://localhost:8001/api/v1/register/ \
-H 'Content-Type: application/json' \
-d '{
"username": "saeed",
"email": "[email protected]",
"password": "saeed"
}'
curl -X POST http://127.0.0.1:8001/api/v1/token/ -H "Content-Type: application/json" -d '{"username": "saeed", "password": "saeed"}'
For other requests check .http file
$ cd deployments
## For The First Time to migrate the database run command
$ docker compose up -d --build
## later use can only use
$ docker compose up -d
- Products to be only added using authorized admin / super user
- list all user paid products with its counts & price