chore: init
This commit is contained in:
199 files changed
+27919
No files matched your search
@@ -0,0 +1,37 @@
|
||||
# Python
|
||||
*.pyc
|
||||
*.pyo
|
||||
*.pyd
|
||||
__pycache__/
|
||||
*.swp
|
||||
|
||||
# Django
|
||||
*.log
|
||||
*.pot
|
||||
*.py[cod]
|
||||
*.sqlite3
|
||||
db.sqlite3
|
||||
/media/
|
||||
*.bak
|
||||
|
||||
# Environment
|
||||
.env
|
||||
*.env
|
||||
*.venv
|
||||
venv/
|
||||
ENV/
|
||||
env/
|
||||
env.bak/
|
||||
*.egg-info/
|
||||
.eggs/
|
||||
|
||||
# IDEs and editors
|
||||
.vscode/
|
||||
.idea/
|
||||
*.sublime-project
|
||||
*.sublime-workspace
|
||||
|
||||
# OS generated files
|
||||
.DS_Store
|
||||
Thumbs.db
|
||||
desktop.ini
|
||||
@@ -0,0 +1 @@
|
||||
3.13
|
||||
@@ -0,0 +1,192 @@
|
||||
## Cart API
|
||||
|
||||
The cart system uses a model-based approach with one-to-one relationship between User and Cart, and one-to-many relationship between Cart and Product through CartItem.
|
||||
|
||||
### Endpoints
|
||||
|
||||
#### Get Cart Items
|
||||
```
|
||||
GET /api/cart/items/
|
||||
```
|
||||
Returns all items in the authenticated user's cart.
|
||||
|
||||
Response:
|
||||
```json
|
||||
{
|
||||
"id": 1,
|
||||
"user": 1,
|
||||
"items": [
|
||||
{
|
||||
"id": 1,
|
||||
"product": 1,
|
||||
"product_name": "Product Name",
|
||||
"product_price": "10.00",
|
||||
"quantity": 2,
|
||||
"subtotal": "20.00",
|
||||
"created_at": "2024-04-23T12:00:00Z",
|
||||
"updated_at": "2024-04-23T12:00:00Z"
|
||||
}
|
||||
],
|
||||
"total": "20.00",
|
||||
"created_at": "2024-04-23T12:00:00Z",
|
||||
"updated_at": "2024-04-23T12:00:00Z"
|
||||
}
|
||||
```
|
||||
|
||||
#### Add Item to Cart
|
||||
```
|
||||
POST /api/cart/add_item/
|
||||
```
|
||||
Adds a product to the cart.
|
||||
|
||||
Request:
|
||||
```json
|
||||
{
|
||||
"product_id": 1,
|
||||
"quantity": 2
|
||||
}
|
||||
```
|
||||
|
||||
Response:
|
||||
```json
|
||||
{
|
||||
"id": 1,
|
||||
"product": 1,
|
||||
"product_name": "Product Name",
|
||||
"product_price": "10.00",
|
||||
"quantity": 2,
|
||||
"subtotal": "20.00",
|
||||
"created_at": "2024-04-23T12:00:00Z",
|
||||
"updated_at": "2024-04-23T12:00:00Z"
|
||||
}
|
||||
```
|
||||
|
||||
#### Remove Item from Cart
|
||||
```
|
||||
POST /api/cart/remove_item/
|
||||
```
|
||||
Removes a product from the cart.
|
||||
|
||||
Request:
|
||||
```json
|
||||
{
|
||||
"product_id": 1
|
||||
}
|
||||
```
|
||||
|
||||
Response:
|
||||
```json
|
||||
{
|
||||
"message": "Item removed from cart"
|
||||
}
|
||||
```
|
||||
|
||||
#### Update Item Quantity
|
||||
```
|
||||
POST /api/cart/update_quantity/
|
||||
```
|
||||
Updates the quantity of a product in the cart.
|
||||
|
||||
Request:
|
||||
```json
|
||||
{
|
||||
"product_id": 1,
|
||||
"quantity": 3
|
||||
}
|
||||
```
|
||||
|
||||
Response:
|
||||
```json
|
||||
{
|
||||
"id": 1,
|
||||
"product": 1,
|
||||
"product_name": "Product Name",
|
||||
"product_price": "10.00",
|
||||
"quantity": 3,
|
||||
"subtotal": "30.00",
|
||||
"created_at": "2024-04-23T12:00:00Z",
|
||||
"updated_at": "2024-04-23T12:00:00Z"
|
||||
}
|
||||
```
|
||||
|
||||
#### Clear Cart
|
||||
```
|
||||
POST /api/cart/clear/
|
||||
```
|
||||
Removes all items from the cart.
|
||||
|
||||
Response:
|
||||
```json
|
||||
{
|
||||
"message": "Cart cleared"
|
||||
}
|
||||
```
|
||||
|
||||
#### Checkout
|
||||
```
|
||||
POST /api/cart/checkout/
|
||||
```
|
||||
Converts the cart to an order.
|
||||
|
||||
Response:
|
||||
```json
|
||||
{
|
||||
"message": "Order created successfully",
|
||||
"order_id": 1
|
||||
}
|
||||
```
|
||||
|
||||
#### Delete Cart
|
||||
```
|
||||
DELETE /api/cart/delete/
|
||||
```
|
||||
Deletes the entire cart and all its items.
|
||||
|
||||
Response:
|
||||
```json
|
||||
{
|
||||
"message": "Cart deleted"
|
||||
}
|
||||
```
|
||||
|
||||
#### Merge Carts
|
||||
```
|
||||
POST /api/cart/merge/
|
||||
```
|
||||
Merges another cart into the current cart. Useful when a user has multiple carts (e.g., from different devices).
|
||||
|
||||
Request:
|
||||
```json
|
||||
{
|
||||
"cart_id": 2
|
||||
}
|
||||
```
|
||||
|
||||
Response:
|
||||
```json
|
||||
{
|
||||
"message": "Carts merged successfully"
|
||||
}
|
||||
```
|
||||
|
||||
### Authentication
|
||||
All cart endpoints require authentication. Users must be logged in to access their cart.
|
||||
|
||||
### Additional Features
|
||||
|
||||
#### Stock Management
|
||||
- The cart system automatically checks product stock availability when:
|
||||
- Adding items to cart
|
||||
- Updating item quantities
|
||||
- Checking out
|
||||
- If there's insufficient stock, the operation will fail with a 400 Bad Request error
|
||||
|
||||
#### Transaction Safety
|
||||
- Cart operations that modify multiple records (like checkout and merge) use database transactions
|
||||
- This ensures data consistency even if an error occurs during the operation
|
||||
|
||||
#### Error Responses
|
||||
- 400 Bad Request: Invalid input data or insufficient stock
|
||||
- 401 Unauthorized: User not authenticated
|
||||
- 403 Forbidden: Attempting to merge carts from different users
|
||||
- 404 Not Found: Product, cart, or cart item not found
|
||||
Whitespace-only changes.
@@ -0,0 +1,106 @@
|
||||
from django.contrib import admin
|
||||
from .models import User, Category, Product, Rating, Order, OrderItem, Cart, CartItem
|
||||
from django.contrib.auth.admin import UserAdmin as BaseUserAdmin
|
||||
|
||||
@admin.register(User)
|
||||
class UserAdmin(BaseUserAdmin):
|
||||
list_display = ('username', 'email', 'first_name', 'last_name', 'is_staff', 'created_at')
|
||||
search_fields = ('username', 'email', 'first_name', 'last_name')
|
||||
list_filter = ('is_staff', 'is_active', 'created_at')
|
||||
readonly_fields = ('created_at', 'updated_at')
|
||||
fieldsets = (
|
||||
('Personal Info', {'fields': ('username', 'first_name', 'last_name', 'email', 'password')}),
|
||||
('Customer Details', {'fields': ('phone', 'address')}),
|
||||
('Permissions', {'fields': ('is_active', 'is_staff', 'is_superuser', 'groups', 'user_permissions')}),
|
||||
('Dates', {'fields': ('created_at', 'updated_at', 'last_login')}),
|
||||
)
|
||||
add_fieldsets = (
|
||||
(None, {
|
||||
'classes': ('wide',),
|
||||
'fields': ('username', 'email', 'first_name', 'last_name', 'password1', 'password2', 'phone', 'address'),
|
||||
}),
|
||||
)
|
||||
|
||||
@admin.register(Category)
|
||||
class CategoryAdmin(admin.ModelAdmin):
|
||||
list_display = ('name', 'created_at')
|
||||
search_fields = ('name',)
|
||||
list_filter = ('created_at',)
|
||||
readonly_fields = ('created_at', 'updated_at')
|
||||
|
||||
|
||||
class RatingInline(admin.TabularInline):
|
||||
model = Rating
|
||||
extra = 0
|
||||
readonly_fields = ('created_at',)
|
||||
|
||||
|
||||
@admin.register(Product)
|
||||
class ProductAdmin(admin.ModelAdmin):
|
||||
list_display = ('name', 'category', 'price','stock','color','size', 'created_at', 'updated_at')
|
||||
search_fields = ('name', 'description')
|
||||
list_filter = ('category', 'created_at')
|
||||
readonly_fields = ('created_at', 'updated_at')
|
||||
inlines = [RatingInline]
|
||||
|
||||
|
||||
@admin.register(Rating)
|
||||
class RatingAdmin(admin.ModelAdmin):
|
||||
list_display = ('user', 'product', 'rating', 'created_at')
|
||||
search_fields = ('user__username', 'product__name', 'comment')
|
||||
list_filter = ('rating', 'created_at')
|
||||
readonly_fields = ('created_at', 'updated_at')
|
||||
|
||||
|
||||
class OrderItemInline(admin.TabularInline):
|
||||
model = OrderItem
|
||||
extra = 0
|
||||
readonly_fields = ('get_subtotal',)
|
||||
|
||||
|
||||
@admin.register(Order)
|
||||
class OrderAdmin(admin.ModelAdmin):
|
||||
list_display = ('id', 'user', 'total_price', 'status', 'created_at')
|
||||
search_fields = ('user__username', 'shipping_address')
|
||||
list_filter = ('status', 'created_at')
|
||||
readonly_fields = ('created_at', 'updated_at', 'total_price')
|
||||
inlines = [OrderItemInline]
|
||||
list_editable = ('status',)
|
||||
|
||||
|
||||
class OrderItemAdmin(admin.ModelAdmin):
|
||||
list_display = ('order', 'product', 'quantity', 'price', 'get_subtotal')
|
||||
list_filter = ('order__status',)
|
||||
search_fields = ('order__id', 'product__name')
|
||||
readonly_fields = ('get_subtotal',)
|
||||
|
||||
def get_subtotal(self, obj):
|
||||
return obj.get_subtotal()
|
||||
get_subtotal.short_description = 'Subtotal'
|
||||
|
||||
|
||||
admin.site.register(OrderItem, OrderItemAdmin)
|
||||
|
||||
|
||||
class CartItemInline(admin.TabularInline):
|
||||
model = CartItem
|
||||
extra = 0
|
||||
readonly_fields = ['created_at', 'updated_at']
|
||||
|
||||
@admin.register(Cart)
|
||||
class CartAdmin(admin.ModelAdmin):
|
||||
list_display = ['user', 'get_total', 'created_at', 'updated_at']
|
||||
list_filter = ['created_at', 'updated_at']
|
||||
search_fields = ['user__username', 'user__email']
|
||||
readonly_fields = ['created_at', 'updated_at']
|
||||
inlines = [CartItemInline]
|
||||
|
||||
def get_total(self, obj):
|
||||
return obj.get_total()
|
||||
get_total.short_description = 'Total'
|
||||
|
||||
def get_subtotal(self, obj):
|
||||
return obj.get_subtotal()
|
||||
get_subtotal.short_description = 'Subtotal'
|
||||
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
from django.apps import AppConfig
|
||||
|
||||
|
||||
class AppConfig(AppConfig):
|
||||
default_auto_field = 'django.db.models.BigAutoField'
|
||||
name = 'app'
|
||||
@@ -0,0 +1,101 @@
|
||||
# In your_app_name/auth.py
|
||||
from rest_framework.authtoken.views import ObtainAuthToken
|
||||
from rest_framework.authtoken.models import Token
|
||||
from rest_framework.views import APIView
|
||||
from rest_framework.response import Response
|
||||
from rest_framework import status
|
||||
from rest_framework.permissions import IsAuthenticated, AllowAny
|
||||
from django.contrib.auth.signals import user_logged_in
|
||||
from django.dispatch import receiver
|
||||
from django.db import transaction
|
||||
from .models import Order, Product, User
|
||||
from django.views.decorators.csrf import csrf_exempt
|
||||
from django.utils.decorators import method_decorator
|
||||
|
||||
@method_decorator(csrf_exempt, name='dispatch')
|
||||
class CustomAuthToken(ObtainAuthToken):
|
||||
permission_classes = [AllowAny]
|
||||
|
||||
def post(self, request, *args, **kwargs):
|
||||
serializer = self.serializer_class(data=request.data, context={'request': request})
|
||||
serializer.is_valid(raise_exception=True)
|
||||
user = serializer.validated_data['user']
|
||||
token, created = Token.objects.get_or_create(user=user)
|
||||
|
||||
# Signal is dispatched automatically by Django's auth system
|
||||
user_logged_in.send(sender=user.__class__, request=request, user=user)
|
||||
|
||||
return Response({
|
||||
'token': token.key,
|
||||
'user_id': user.pk,
|
||||
'username': user.username,
|
||||
'email': user.email,
|
||||
'first_name': user.first_name,
|
||||
'last_name': user.last_name,
|
||||
})
|
||||
|
||||
class LogoutView(APIView):
|
||||
permission_classes = [AllowAny]
|
||||
|
||||
def post(self, request):
|
||||
# Allow logout by token or user_id
|
||||
user_id = request.data.get('user_id')
|
||||
token_key = request.data.get('token')
|
||||
|
||||
if user_id:
|
||||
try:
|
||||
user = User.objects.get(id=user_id)
|
||||
try:
|
||||
user.auth_token.delete()
|
||||
except Token.DoesNotExist:
|
||||
pass
|
||||
return Response({"detail": "Successfully logged out."}, status=status.HTTP_200_OK)
|
||||
except User.DoesNotExist:
|
||||
return Response({"detail": "User not found."}, status=status.HTTP_404_NOT_FOUND)
|
||||
elif token_key:
|
||||
try:
|
||||
token = Token.objects.get(key=token_key)
|
||||
token.delete()
|
||||
return Response({"detail": "Successfully logged out."}, status=status.HTTP_200_OK)
|
||||
except Token.DoesNotExist:
|
||||
return Response({"detail": "Invalid token."}, status=status.HTTP_400_BAD_REQUEST)
|
||||
elif request.user.is_authenticated:
|
||||
# Delete the token to logout the current user
|
||||
request.user.auth_token.delete()
|
||||
return Response({"detail": "Successfully logged out."}, status=status.HTTP_200_OK)
|
||||
else:
|
||||
return Response({"detail": "Authentication credentials not provided."},
|
||||
status=status.HTTP_400_BAD_REQUEST)
|
||||
|
||||
@receiver(user_logged_in)
|
||||
def sync_cart_on_login(sender, request, user, **kwargs):
|
||||
"""Sync session cart to user's cart when they log in"""
|
||||
if not hasattr(request, 'session') or not request.session.get('cart'):
|
||||
return
|
||||
|
||||
cart = request.session.get('cart', {})
|
||||
if not cart:
|
||||
return
|
||||
|
||||
with transaction.atomic():
|
||||
# Get or create a pending order
|
||||
pending_order, created = Order.objects.get_or_create(
|
||||
user=user,
|
||||
status='Pending',
|
||||
defaults={
|
||||
'shipping_address': user.address or ''
|
||||
}
|
||||
)
|
||||
|
||||
# Add session cart items to the user's order
|
||||
for product_id, item_data in cart.items():
|
||||
try:
|
||||
product = Product.objects.get(id=product_id)
|
||||
quantity = item_data.get('quantity', 1)
|
||||
pending_order.add_product(product, quantity)
|
||||
except Product.DoesNotExist:
|
||||
continue
|
||||
|
||||
# Clear the session cart
|
||||
request.session['cart'] = {}
|
||||
request.session.modified = True
|
||||
@@ -0,0 +1,198 @@
|
||||
from rest_framework import viewsets, status
|
||||
from rest_framework.decorators import action
|
||||
from rest_framework.response import Response
|
||||
from rest_framework.permissions import IsAuthenticated
|
||||
from django.shortcuts import get_object_or_404
|
||||
from django.db import transaction
|
||||
from .models import Cart, CartItem, Product, Order, OrderItem
|
||||
from .serializers import CartSerializer, CartItemSerializer
|
||||
|
||||
class CartViewSet(viewsets.ViewSet):
|
||||
permission_classes = [IsAuthenticated]
|
||||
|
||||
def get_cart(self, request):
|
||||
"""Get or create cart for the authenticated user"""
|
||||
cart, created = Cart.objects.get_or_create(user=request.user)
|
||||
return cart
|
||||
|
||||
@action(detail=False, methods=['get'])
|
||||
def items(self, request):
|
||||
"""Get all items in the cart"""
|
||||
cart = self.get_cart(request)
|
||||
serializer = CartSerializer(cart, context={'request': request})
|
||||
return Response(serializer.data)
|
||||
|
||||
@action(detail=False, methods=['post'])
|
||||
def add_item(self, request):
|
||||
"""Add an item to the cart"""
|
||||
product_id = request.data.get('product_id')
|
||||
quantity = int(request.data.get('quantity', 1))
|
||||
|
||||
if not product_id:
|
||||
return Response({'error': 'Product ID is required'}, status=status.HTTP_400_BAD_REQUEST)
|
||||
|
||||
try:
|
||||
product = Product.objects.get(id=product_id)
|
||||
except Product.DoesNotExist:
|
||||
return Response({'error': 'Product not found'}, status=status.HTTP_404_NOT_FOUND)
|
||||
|
||||
# Check if product is in stock
|
||||
if product.stock < quantity:
|
||||
return Response({
|
||||
'error': f'Not enough stock available. Available: {product.stock}'
|
||||
}, status=status.HTTP_400_BAD_REQUEST)
|
||||
|
||||
cart = self.get_cart(request)
|
||||
cart_item = cart.add_product(product, quantity)
|
||||
|
||||
if cart_item:
|
||||
serializer = CartItemSerializer(cart_item, context={'request': request})
|
||||
return Response(serializer.data, status=status.HTTP_201_CREATED)
|
||||
return Response({'error': 'Invalid quantity'}, status=status.HTTP_400_BAD_REQUEST)
|
||||
|
||||
@action(detail=False, methods=['post'])
|
||||
def remove_item(self, request):
|
||||
"""Remove an item from the cart"""
|
||||
try:
|
||||
product_id = request.data.get('product_id')
|
||||
if not product_id:
|
||||
return Response({'error': 'Product ID is required'}, status=status.HTTP_400_BAD_REQUEST)
|
||||
|
||||
try:
|
||||
product = Product.objects.get(id=product_id)
|
||||
except Product.DoesNotExist:
|
||||
return Response({'error': 'Product not found'}, status=status.HTTP_404_NOT_FOUND)
|
||||
|
||||
cart = self.get_cart(request)
|
||||
cart_item = CartItem.objects.filter(cart=cart, product=product).first()
|
||||
|
||||
if cart_item:
|
||||
cart_item.delete()
|
||||
return Response({'message': 'Item removed from cart successfully'})
|
||||
return Response({'error': 'Item not found in cart'}, status=status.HTTP_404_NOT_FOUND)
|
||||
except Exception as e:
|
||||
return Response({'error': str(e)}, status=status.HTTP_400_BAD_REQUEST)
|
||||
|
||||
@action(detail=False, methods=['post'])
|
||||
def update_quantity(self, request):
|
||||
"""Update the quantity of an item in the cart"""
|
||||
try:
|
||||
product_id = request.data.get('product_id')
|
||||
quantity = int(request.data.get('quantity', 1))
|
||||
|
||||
if not product_id:
|
||||
return Response({'error': 'Product ID is required'}, status=status.HTTP_400_BAD_REQUEST)
|
||||
|
||||
if quantity <= 0:
|
||||
return Response({'error': 'Quantity must be greater than 0'}, status=status.HTTP_400_BAD_REQUEST)
|
||||
|
||||
try:
|
||||
product = Product.objects.get(id=product_id)
|
||||
except Product.DoesNotExist:
|
||||
return Response({'error': 'Product not found'}, status=status.HTTP_404_NOT_FOUND)
|
||||
|
||||
# Check if product is in stock
|
||||
if product.stock < quantity:
|
||||
return Response({
|
||||
'error': f'Not enough stock available. Available: {product.stock}'
|
||||
}, status=status.HTTP_400_BAD_REQUEST)
|
||||
|
||||
cart = self.get_cart(request)
|
||||
try:
|
||||
cart_item = CartItem.objects.get(cart=cart, product=product)
|
||||
cart_item.quantity = quantity
|
||||
cart_item.save()
|
||||
serializer = CartItemSerializer(cart_item, context={'request': request})
|
||||
return Response(serializer.data)
|
||||
except CartItem.DoesNotExist:
|
||||
return Response({'error': 'Item not found in cart'}, status=status.HTTP_404_NOT_FOUND)
|
||||
except Exception as e:
|
||||
return Response({'error': str(e)}, status=status.HTTP_400_BAD_REQUEST)
|
||||
|
||||
@action(detail=False, methods=['post'])
|
||||
def clear(self, request):
|
||||
"""Clear all items from the cart"""
|
||||
cart = self.get_cart(request)
|
||||
cart.clear()
|
||||
return Response({'message': 'Cart cleared'})
|
||||
|
||||
@action(detail=False, methods=['delete'])
|
||||
def delete(self, request):
|
||||
"""Delete the entire cart"""
|
||||
cart = self.get_cart(request)
|
||||
cart.delete()
|
||||
return Response({'message': 'Cart deleted'}, status=status.HTTP_204_NO_CONTENT)
|
||||
|
||||
@action(detail=False, methods=['post'])
|
||||
def checkout(self, request):
|
||||
"""Convert cart to order"""
|
||||
cart = self.get_cart(request)
|
||||
|
||||
if not cart.items.exists():
|
||||
return Response({'error': 'Cart is empty'}, status=status.HTTP_400_BAD_REQUEST)
|
||||
|
||||
# Check stock availability for all items
|
||||
for cart_item in cart.items.all():
|
||||
if cart_item.product.stock < cart_item.quantity:
|
||||
return Response({
|
||||
'error': f'Not enough stock for {cart_item.product.name}. Available: {cart_item.product.stock}'
|
||||
}, status=status.HTTP_400_BAD_REQUEST)
|
||||
|
||||
with transaction.atomic():
|
||||
# Create order from cart
|
||||
order = Order.objects.create(
|
||||
user=request.user,
|
||||
status='Pending',
|
||||
shipping_address=request.user.address or '',
|
||||
total_price=cart.get_total()
|
||||
)
|
||||
|
||||
# Add cart items to order
|
||||
for cart_item in cart.items.all():
|
||||
OrderItem.objects.create(
|
||||
order=order,
|
||||
product=cart_item.product,
|
||||
quantity=cart_item.quantity,
|
||||
price=cart_item.product.price
|
||||
)
|
||||
|
||||
# Update product stock
|
||||
product = cart_item.product
|
||||
product.stock -= cart_item.quantity
|
||||
product.save()
|
||||
|
||||
# Clear the cart
|
||||
cart.clear()
|
||||
|
||||
return Response({
|
||||
'message': 'Order created successfully',
|
||||
'order_id': order.id
|
||||
}, status=status.HTTP_201_CREATED)
|
||||
|
||||
@action(detail=False, methods=['post'])
|
||||
def merge(self, request):
|
||||
"""Merge another cart into the current cart"""
|
||||
other_cart_id = request.data.get('cart_id')
|
||||
|
||||
if not other_cart_id:
|
||||
return Response({'error': 'Cart ID is required'}, status=status.HTTP_400_BAD_REQUEST)
|
||||
|
||||
try:
|
||||
other_cart = Cart.objects.get(id=other_cart_id)
|
||||
except Cart.DoesNotExist:
|
||||
return Response({'error': 'Cart not found'}, status=status.HTTP_404_NOT_FOUND)
|
||||
|
||||
if other_cart.user != request.user:
|
||||
return Response({'error': 'Cannot merge carts from different users'},
|
||||
status=status.HTTP_403_FORBIDDEN)
|
||||
|
||||
current_cart = self.get_cart(request)
|
||||
|
||||
with transaction.atomic():
|
||||
for cart_item in other_cart.items.all():
|
||||
current_cart.add_product(cart_item.product, cart_item.quantity)
|
||||
|
||||
# Delete the other cart
|
||||
other_cart.delete()
|
||||
|
||||
return Response({'message': 'Carts merged successfully'})
|
||||
@@ -0,0 +1,11 @@
|
||||
class AnonymousCartMiddleware:
|
||||
def __init__(self, get_response):
|
||||
self.get_response = get_response
|
||||
|
||||
def __call__(self, request):
|
||||
# Initialize cart for anonymous users
|
||||
if not request.user.is_authenticated and 'cart' not in request.session:
|
||||
request.session['cart'] = {}
|
||||
|
||||
response = self.get_response(request)
|
||||
return response
|
||||
@@ -0,0 +1,129 @@
|
||||
# Generated by Django 5.2 on 2025-04-20 06:29
|
||||
|
||||
import django.db.models.deletion
|
||||
from django.conf import settings
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
initial = True
|
||||
|
||||
dependencies = [
|
||||
('auth', '0012_alter_user_first_name_max_length'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.CreateModel(
|
||||
name='Category',
|
||||
fields=[
|
||||
('id', models.BigAutoField(primary_key=True, serialize=False)),
|
||||
('name', models.CharField(max_length=100, unique=True)),
|
||||
('image', models.ImageField(upload_to='categories/')),
|
||||
('created_at', models.DateTimeField(auto_now_add=True)),
|
||||
('updated_at', models.DateTimeField(auto_now=True)),
|
||||
],
|
||||
options={
|
||||
'verbose_name': 'Category',
|
||||
'verbose_name_plural': 'Categories',
|
||||
'ordering': ['name'],
|
||||
},
|
||||
),
|
||||
migrations.CreateModel(
|
||||
name='User',
|
||||
fields=[
|
||||
('password', models.CharField(max_length=128, verbose_name='password')),
|
||||
('last_login', models.DateTimeField(blank=True, null=True, verbose_name='last login')),
|
||||
('is_superuser', models.BooleanField(default=False, help_text='Designates that this user has all permissions without explicitly assigning them.', verbose_name='superuser status')),
|
||||
('id', models.BigAutoField(primary_key=True, serialize=False)),
|
||||
('username', models.CharField(max_length=150, unique=True)),
|
||||
('first_name', models.CharField(max_length=30)),
|
||||
('last_name', models.CharField(max_length=30)),
|
||||
('email', models.EmailField(max_length=254, unique=True)),
|
||||
('is_active', models.BooleanField(default=True)),
|
||||
('is_staff', models.BooleanField(default=False)),
|
||||
('phone', models.CharField(blank=True, max_length=15, null=True)),
|
||||
('address', models.TextField(blank=True, null=True)),
|
||||
('created_at', models.DateTimeField(auto_now_add=True)),
|
||||
('updated_at', models.DateTimeField(auto_now=True)),
|
||||
('groups', models.ManyToManyField(blank=True, help_text='The groups this user belongs to. A user will get all permissions granted to each of their groups.', related_name='user_set', related_query_name='user', to='auth.group', verbose_name='groups')),
|
||||
('user_permissions', models.ManyToManyField(blank=True, help_text='Specific permissions for this user.', related_name='user_set', related_query_name='user', to='auth.permission', verbose_name='user permissions')),
|
||||
],
|
||||
options={
|
||||
'verbose_name': 'User',
|
||||
'verbose_name_plural': 'Users',
|
||||
'ordering': ['username'],
|
||||
},
|
||||
),
|
||||
migrations.CreateModel(
|
||||
name='Order',
|
||||
fields=[
|
||||
('id', models.AutoField(primary_key=True, serialize=False)),
|
||||
('total_price', models.DecimalField(decimal_places=2, default=0, max_digits=10)),
|
||||
('status', models.CharField(choices=[('Pending', 'Pending'), ('Shipped', 'Shipped'), ('Delivered', 'Delivered'), ('Cancelled', 'Cancelled')], default='Pending', max_length=20)),
|
||||
('shipping_address', models.CharField(blank=True, max_length=255)),
|
||||
('created_at', models.DateTimeField(auto_now_add=True)),
|
||||
('updated_at', models.DateTimeField(auto_now=True)),
|
||||
('user', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='orders', to=settings.AUTH_USER_MODEL)),
|
||||
],
|
||||
options={
|
||||
'verbose_name': 'Order',
|
||||
'verbose_name_plural': 'Orders',
|
||||
'ordering': ['-created_at'],
|
||||
},
|
||||
),
|
||||
migrations.CreateModel(
|
||||
name='Product',
|
||||
fields=[
|
||||
('id', models.BigAutoField(primary_key=True, serialize=False)),
|
||||
('name', models.CharField(max_length=100)),
|
||||
('description', models.TextField()),
|
||||
('price', models.DecimalField(decimal_places=2, max_digits=10)),
|
||||
('image', models.ImageField(upload_to='products/')),
|
||||
('size', models.CharField(blank=True, max_length=10, null=True)),
|
||||
('color', models.CharField(blank=True, max_length=20, null=True)),
|
||||
('stock', models.IntegerField(default=0)),
|
||||
('created_at', models.DateTimeField(auto_now_add=True)),
|
||||
('updated_at', models.DateTimeField(auto_now=True)),
|
||||
('category', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='products', to='app.category')),
|
||||
],
|
||||
options={
|
||||
'verbose_name': 'Product',
|
||||
'verbose_name_plural': 'Products',
|
||||
'ordering': ['name'],
|
||||
},
|
||||
),
|
||||
migrations.CreateModel(
|
||||
name='OrderItem',
|
||||
fields=[
|
||||
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||
('quantity', models.IntegerField()),
|
||||
('price', models.DecimalField(blank=True, decimal_places=2, max_digits=10, null=True)),
|
||||
('order', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='order_items', to='app.order')),
|
||||
('product', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='order_items', to='app.product')),
|
||||
],
|
||||
options={
|
||||
'verbose_name': 'Order Item',
|
||||
'verbose_name_plural': 'Order Items',
|
||||
'ordering': ['order'],
|
||||
},
|
||||
),
|
||||
migrations.CreateModel(
|
||||
name='Rating',
|
||||
fields=[
|
||||
('id', models.BigAutoField(primary_key=True, serialize=False)),
|
||||
('rating', models.IntegerField()),
|
||||
('comment', models.TextField(blank=True, null=True)),
|
||||
('created_at', models.DateTimeField(auto_now_add=True)),
|
||||
('updated_at', models.DateTimeField(auto_now=True)),
|
||||
('product', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='ratings', to='app.product')),
|
||||
('user', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='ratings', to=settings.AUTH_USER_MODEL)),
|
||||
],
|
||||
options={
|
||||
'verbose_name': 'Rating',
|
||||
'verbose_name_plural': 'Ratings',
|
||||
'ordering': ['-created_at'],
|
||||
'unique_together': {('product', 'user')},
|
||||
},
|
||||
),
|
||||
]
|
||||
@@ -0,0 +1,46 @@
|
||||
# Generated by Django 5.2 on 2025-04-23 06:22
|
||||
|
||||
import django.db.models.deletion
|
||||
from django.conf import settings
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('app', '0001_initial'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.CreateModel(
|
||||
name='Cart',
|
||||
fields=[
|
||||
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||
('created_at', models.DateTimeField(auto_now_add=True)),
|
||||
('updated_at', models.DateTimeField(auto_now=True)),
|
||||
('user', models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, related_name='cart', to=settings.AUTH_USER_MODEL)),
|
||||
],
|
||||
options={
|
||||
'verbose_name': 'Cart',
|
||||
'verbose_name_plural': 'Carts',
|
||||
'ordering': ['-updated_at'],
|
||||
},
|
||||
),
|
||||
migrations.CreateModel(
|
||||
name='CartItem',
|
||||
fields=[
|
||||
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||
('quantity', models.PositiveIntegerField(default=1)),
|
||||
('created_at', models.DateTimeField(auto_now_add=True)),
|
||||
('updated_at', models.DateTimeField(auto_now=True)),
|
||||
('cart', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='items', to='app.cart')),
|
||||
('product', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='cart_items', to='app.product')),
|
||||
],
|
||||
options={
|
||||
'verbose_name': 'Cart Item',
|
||||
'verbose_name_plural': 'Cart Items',
|
||||
'ordering': ['-updated_at'],
|
||||
'unique_together': {('cart', 'product')},
|
||||
},
|
||||
),
|
||||
]
|
||||
@@ -0,0 +1,58 @@
|
||||
# Generated by Django 5.2 on 2025-04-23 12:23
|
||||
|
||||
import django.core.validators
|
||||
import django.db.models.deletion
|
||||
from django.conf import settings
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('app', '0002_cart_cartitem'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name='category',
|
||||
name='description',
|
||||
field=models.TextField(blank=True),
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='product',
|
||||
name='average_rating',
|
||||
field=models.DecimalField(decimal_places=2, default=0, max_digits=3),
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='user',
|
||||
name='phone_number',
|
||||
field=models.CharField(blank=True, max_length=15, null=True),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='category',
|
||||
name='image',
|
||||
field=models.ImageField(blank=True, null=True, upload_to='categories/'),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='product',
|
||||
name='image',
|
||||
field=models.ImageField(blank=True, null=True, upload_to='products/'),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='rating',
|
||||
name='rating',
|
||||
field=models.IntegerField(validators=[django.core.validators.MinValueValidator(1), django.core.validators.MaxValueValidator(5)]),
|
||||
),
|
||||
migrations.CreateModel(
|
||||
name='Favorite',
|
||||
fields=[
|
||||
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||
('created_at', models.DateTimeField(auto_now_add=True)),
|
||||
('product', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='favorites', to='app.product')),
|
||||
('user', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='favorites', to=settings.AUTH_USER_MODEL)),
|
||||
],
|
||||
options={
|
||||
'unique_together': {('user', 'product')},
|
||||
},
|
||||
),
|
||||
]
|
||||
Whitespace-only changes.
@@ -0,0 +1,334 @@
|
||||
from django.db import models
|
||||
from django.contrib.auth.hashers import make_password, check_password
|
||||
from django.dispatch import receiver
|
||||
from rest_framework.authtoken.models import Token
|
||||
from django.db.models.signals import post_save
|
||||
from django.contrib.auth.models import AbstractBaseUser, BaseUserManager, PermissionsMixin
|
||||
from django.core.validators import MinValueValidator, MaxValueValidator
|
||||
|
||||
class UserManager(BaseUserManager):
|
||||
def create_user(self, username, email, password=None, **extra_fields):
|
||||
if not email:
|
||||
raise ValueError('Users must have an email address')
|
||||
if not username:
|
||||
raise ValueError('Users must have a username')
|
||||
|
||||
email = self.normalize_email(email)
|
||||
user = self.model(
|
||||
username=username,
|
||||
email=email,
|
||||
**extra_fields
|
||||
)
|
||||
user.set_password(password)
|
||||
user.save(using=self._db)
|
||||
return user
|
||||
|
||||
def create_superuser(self, username, email, password=None, **extra_fields):
|
||||
extra_fields.setdefault('is_staff', True)
|
||||
extra_fields.setdefault('is_superuser', True)
|
||||
|
||||
return self.create_user(username, email, password, **extra_fields)
|
||||
|
||||
class User(AbstractBaseUser, PermissionsMixin):
|
||||
id = models.BigAutoField(primary_key=True)
|
||||
username = models.CharField(max_length=150, unique=True)
|
||||
first_name = models.CharField(max_length=30)
|
||||
last_name = models.CharField(max_length=30)
|
||||
email = models.EmailField(unique=True)
|
||||
is_active = models.BooleanField(default=True)
|
||||
is_staff = models.BooleanField(default=False)
|
||||
phone = models.CharField(max_length=15, blank=True, null=True)
|
||||
address = models.TextField(blank=True, null=True)
|
||||
created_at = models.DateTimeField(auto_now_add=True)
|
||||
updated_at = models.DateTimeField(auto_now=True)
|
||||
phone_number = models.CharField(max_length=15, blank=True, null=True)
|
||||
|
||||
objects = UserManager()
|
||||
|
||||
USERNAME_FIELD = 'username'
|
||||
EMAIL_FIELD = 'email'
|
||||
REQUIRED_FIELDS = ['email', 'first_name', 'last_name']
|
||||
|
||||
def __str__(self):
|
||||
return self.username
|
||||
|
||||
def set_password(self, raw_password):
|
||||
self.password = make_password(raw_password)
|
||||
|
||||
def check_password(self, raw_password):
|
||||
return check_password(raw_password, self.password)
|
||||
|
||||
class Meta:
|
||||
verbose_name = 'User'
|
||||
verbose_name_plural = 'Users'
|
||||
ordering = ['username']
|
||||
|
||||
def get_full_name(self):
|
||||
return f"{self.first_name} {self.last_name}"
|
||||
|
||||
def get_short_name(self):
|
||||
return self.first_name
|
||||
|
||||
@receiver(post_save, sender=User)
|
||||
def create_auth_token(sender, instance=None, created=False, **kwargs):
|
||||
if created:
|
||||
Token.objects.create(user=instance)
|
||||
|
||||
class Category(models.Model):
|
||||
id = models.BigAutoField(primary_key=True)
|
||||
name = models.CharField(max_length=100, unique=True)
|
||||
image = models.ImageField(upload_to='categories/', blank=True, null=True)
|
||||
description = models.TextField(blank=True)
|
||||
created_at = models.DateTimeField(auto_now_add=True)
|
||||
updated_at = models.DateTimeField(auto_now=True)
|
||||
|
||||
def __str__(self):
|
||||
return self.name
|
||||
class Meta:
|
||||
verbose_name = 'Category'
|
||||
verbose_name_plural = 'Categories'
|
||||
ordering = ['name']
|
||||
@property
|
||||
def image_url(self):
|
||||
if self.image:
|
||||
return f'/media/{self.image.name}'
|
||||
return None
|
||||
|
||||
class Product(models.Model):
|
||||
id = models.BigAutoField(primary_key= True)
|
||||
name = models.CharField(max_length=100)
|
||||
description = models.TextField()
|
||||
price = models.DecimalField(max_digits=10, decimal_places=2)
|
||||
image = models.ImageField(upload_to='products/', blank=True, null=True)
|
||||
category = models.ForeignKey(Category, related_name='products', on_delete=models.CASCADE)
|
||||
size = models.CharField(max_length=10, blank=True, null=True)
|
||||
color = models.CharField(max_length=20, blank=True, null=True)
|
||||
stock = models.IntegerField(default=0)
|
||||
created_at = models.DateTimeField(auto_now_add=True)
|
||||
updated_at = models.DateTimeField(auto_now=True)
|
||||
average_rating = models.DecimalField(max_digits=3, decimal_places=2, default=0)
|
||||
|
||||
def __str__(self):
|
||||
return self.name
|
||||
class Meta:
|
||||
verbose_name = 'Product'
|
||||
verbose_name_plural = 'Products'
|
||||
ordering = ['name']
|
||||
@property
|
||||
def image_url(self):
|
||||
if self.image:
|
||||
return f'/media/{self.image.name}'
|
||||
return None
|
||||
|
||||
def update_average_rating(self):
|
||||
avg_rating = self.ratings.aggregate(avg_rating=models.Avg('rating'))['avg_rating']
|
||||
self.average_rating = avg_rating or 0
|
||||
self.save()
|
||||
|
||||
class Rating(models.Model):
|
||||
id = models.BigAutoField(primary_key= True)
|
||||
product = models.ForeignKey(Product, related_name='ratings', on_delete=models.CASCADE)
|
||||
user = models.ForeignKey(User, related_name='ratings', on_delete=models.CASCADE)
|
||||
rating = models.IntegerField(validators=[MinValueValidator(1), MaxValueValidator(5)])
|
||||
comment = models.TextField(blank=True, null=True)
|
||||
created_at = models.DateTimeField(auto_now_add=True)
|
||||
updated_at = models.DateTimeField(auto_now=True)
|
||||
class Meta:
|
||||
unique_together = ('product', 'user')
|
||||
verbose_name = 'Rating'
|
||||
verbose_name_plural = 'Ratings'
|
||||
ordering = ['-created_at']
|
||||
|
||||
def __str__(self):
|
||||
return f'{self.user.username} - {self.product.name} - {self.rating}'
|
||||
|
||||
class Order(models.Model):
|
||||
id = models.AutoField(primary_key=True)
|
||||
user = models.ForeignKey(User, related_name='orders', on_delete=models.CASCADE)
|
||||
total_price = models.DecimalField(max_digits=10, decimal_places=2, default=0)
|
||||
status = models.CharField(max_length=20, default='Pending', choices=[
|
||||
('Pending', 'Pending'),
|
||||
('Shipped', 'Shipped'),
|
||||
('Delivered', 'Delivered'),
|
||||
('Cancelled', 'Cancelled')
|
||||
])
|
||||
shipping_address = models.CharField(max_length=255, blank=True)
|
||||
created_at = models.DateTimeField(auto_now_add=True)
|
||||
updated_at = models.DateTimeField(auto_now=True)
|
||||
|
||||
def __str__(self):
|
||||
return f'Order {self.id} by {self.user.username}'
|
||||
|
||||
def update_total(self):
|
||||
"""Automatically calculate total price from order items"""
|
||||
order_items = self.order_items.all()
|
||||
if not order_items.exists():
|
||||
self.total_price = 0
|
||||
else:
|
||||
self.total_price = sum(item.get_subtotal() for item in order_items)
|
||||
self.save()
|
||||
|
||||
def add_product(self, product, quantity=1):
|
||||
"""Add a product to the order"""
|
||||
if product is None:
|
||||
return None
|
||||
|
||||
if quantity is None or quantity <= 0:
|
||||
quantity = 1
|
||||
|
||||
order_item, created = OrderItem.objects.get_or_create(
|
||||
order=self,
|
||||
product=product,
|
||||
defaults={
|
||||
'quantity': quantity,
|
||||
'price': product.price if product.price else 0
|
||||
}
|
||||
)
|
||||
|
||||
if not created:
|
||||
order_item.quantity += quantity
|
||||
order_item.save()
|
||||
|
||||
self.update_total()
|
||||
return order_item
|
||||
|
||||
class Meta:
|
||||
verbose_name = 'Order'
|
||||
verbose_name_plural = 'Orders'
|
||||
ordering = ['-created_at']
|
||||
|
||||
class OrderItem(models.Model):
|
||||
order = models.ForeignKey(Order, related_name='order_items', on_delete=models.CASCADE)
|
||||
product = models.ForeignKey(Product, related_name='order_items', on_delete=models.CASCADE)
|
||||
quantity = models.IntegerField()
|
||||
price = models.DecimalField(max_digits=10, decimal_places=2, null=True, blank=True)
|
||||
|
||||
def get_subtotal(self):
|
||||
"""Calculate the subtotal for this item"""
|
||||
if self.price is None or self.quantity is None:
|
||||
return 0
|
||||
return self.price * self.quantity
|
||||
|
||||
def __str__(self):
|
||||
return f'{self.product.name} - {self.quantity}'
|
||||
|
||||
def save(self, *args, **kwargs):
|
||||
# Ensure price is set correctly if it's none or a new order item
|
||||
if self.price is None or (not self.pk and not self.price):
|
||||
self.price = self.product.price if self.product and self.product.price else 0
|
||||
|
||||
# Ensure quantity is never None
|
||||
if self.quantity is None:
|
||||
self.quantity = 1
|
||||
|
||||
super().save(*args, **kwargs)
|
||||
# Update the order total when an item is saved
|
||||
if self.order:
|
||||
self.order.update_total()
|
||||
|
||||
def delete(self, *args, **kwargs):
|
||||
order = self.order
|
||||
super().delete(*args, **kwargs)
|
||||
# Update the order total when an item is deleted
|
||||
if order:
|
||||
order.update_total()
|
||||
|
||||
class Meta:
|
||||
verbose_name = 'Order Item'
|
||||
verbose_name_plural = 'Order Items'
|
||||
ordering = ['order']
|
||||
|
||||
@receiver(post_save, sender=Order)
|
||||
def update_order_status(sender, instance, created, **kwargs):
|
||||
"""When an order status changes to Delivered, update product stock"""
|
||||
if not created and instance.status == 'Delivered':
|
||||
for item in instance.order_items.all():
|
||||
product = item.product
|
||||
# Only update stock if we haven't already updated it
|
||||
if product.stock >= item.quantity:
|
||||
product.stock -= item.quantity
|
||||
product.save()
|
||||
|
||||
class Cart(models.Model):
|
||||
user = models.OneToOneField(User, related_name='cart', on_delete=models.CASCADE)
|
||||
created_at = models.DateTimeField(auto_now_add=True)
|
||||
updated_at = models.DateTimeField(auto_now=True)
|
||||
|
||||
def __str__(self):
|
||||
return f"Cart for {self.user.username}"
|
||||
|
||||
def get_total(self):
|
||||
"""Calculate total price of all items in cart"""
|
||||
return sum(item.get_subtotal() for item in self.items.all())
|
||||
|
||||
def add_product(self, product, quantity=1):
|
||||
"""Add a product to the cart"""
|
||||
if quantity <= 0:
|
||||
return None
|
||||
|
||||
cart_item, created = CartItem.objects.get_or_create(
|
||||
cart=self,
|
||||
product=product,
|
||||
defaults={'quantity': quantity}
|
||||
)
|
||||
|
||||
if not created:
|
||||
cart_item.quantity += quantity
|
||||
cart_item.save()
|
||||
|
||||
return cart_item
|
||||
|
||||
def remove_product(self, product):
|
||||
"""Remove a product from the cart"""
|
||||
try:
|
||||
cart_item = CartItem.objects.get(cart=self, product=product)
|
||||
cart_item.delete()
|
||||
return True
|
||||
except CartItem.DoesNotExist:
|
||||
return False
|
||||
|
||||
def clear(self):
|
||||
"""Remove all items from the cart"""
|
||||
self.items.all().delete()
|
||||
|
||||
class Meta:
|
||||
verbose_name = 'Cart'
|
||||
verbose_name_plural = 'Carts'
|
||||
ordering = ['-updated_at']
|
||||
|
||||
class CartItem(models.Model):
|
||||
cart = models.ForeignKey(Cart, related_name='items', on_delete=models.CASCADE)
|
||||
product = models.ForeignKey(Product, related_name='cart_items', on_delete=models.CASCADE)
|
||||
quantity = models.PositiveIntegerField(default=1)
|
||||
created_at = models.DateTimeField(auto_now_add=True)
|
||||
updated_at = models.DateTimeField(auto_now=True)
|
||||
|
||||
def __str__(self):
|
||||
return f"{self.quantity} x {self.product.name} in {self.cart}"
|
||||
|
||||
def get_subtotal(self):
|
||||
"""Calculate the subtotal for this item"""
|
||||
return self.product.price * self.quantity
|
||||
|
||||
class Meta:
|
||||
verbose_name = 'Cart Item'
|
||||
verbose_name_plural = 'Cart Items'
|
||||
ordering = ['-updated_at']
|
||||
unique_together = ['cart', 'product']
|
||||
|
||||
@receiver(post_save, sender=User)
|
||||
def create_user_cart(sender, instance, created, **kwargs):
|
||||
"""Create a cart for new users"""
|
||||
if created:
|
||||
Cart.objects.create(user=instance)
|
||||
|
||||
class Favorite(models.Model):
|
||||
user = models.ForeignKey(User, on_delete=models.CASCADE, related_name='favorites')
|
||||
product = models.ForeignKey(Product, on_delete=models.CASCADE, related_name='favorites')
|
||||
created_at = models.DateTimeField(auto_now_add=True)
|
||||
|
||||
class Meta:
|
||||
unique_together = ['user', 'product']
|
||||
|
||||
def __str__(self):
|
||||
return f"{self.user.username}'s favorite: {self.product.name}"
|
||||
@@ -0,0 +1,25 @@
|
||||
from rest_framework import permissions
|
||||
|
||||
class IsOwnerOrAdmin(permissions.BasePermission):
|
||||
"""
|
||||
Custom permission to only allow owners of an object or admins to edit it.
|
||||
"""
|
||||
def has_object_permission(self, request, view, obj):
|
||||
# Read permissions are allowed to any request,
|
||||
# so we'll always allow GET, HEAD or OPTIONS requests.
|
||||
if request.method in permissions.SAFE_METHODS:
|
||||
return True
|
||||
|
||||
# Admin can do anything
|
||||
if request.user.is_staff:
|
||||
return True
|
||||
|
||||
# Instance must have an attribute named `user`.
|
||||
if hasattr(obj, 'user'):
|
||||
return obj.user == request.user
|
||||
|
||||
# If object is a User, check if it's the current user
|
||||
if hasattr(obj, 'username'):
|
||||
return obj == request.user
|
||||
|
||||
return False
|
||||
@@ -0,0 +1,178 @@
|
||||
from rest_framework import serializers
|
||||
from .models import User, Category, Product, Rating, Order, OrderItem, CartItem, Cart, Favorite
|
||||
|
||||
class UserSerializer(serializers.ModelSerializer):
|
||||
password = serializers.CharField(write_only=True)
|
||||
|
||||
class Meta:
|
||||
model = User
|
||||
fields = ['id', 'username', 'first_name', 'last_name', 'email', 'password',
|
||||
'phone', 'address', 'created_at']
|
||||
read_only_fields = ['id', 'created_at']
|
||||
|
||||
def create(self, validated_data):
|
||||
# Use the create_user method instead of direct creation
|
||||
user = User.objects.create_user(
|
||||
username=validated_data['username'],
|
||||
email=validated_data['email'],
|
||||
password=validated_data['password'],
|
||||
first_name=validated_data.get('first_name', ''),
|
||||
last_name=validated_data.get('last_name', ''),
|
||||
phone=validated_data.get('phone', ''),
|
||||
address=validated_data.get('address', '')
|
||||
)
|
||||
return user
|
||||
|
||||
|
||||
class CategorySerializer(serializers.ModelSerializer):
|
||||
class Meta:
|
||||
model = Category
|
||||
fields = ['id', 'name', 'image', 'created_at']
|
||||
read_only_fields = ['id', 'created_at']
|
||||
|
||||
|
||||
class RatingSerializer(serializers.ModelSerializer):
|
||||
username = serializers.ReadOnlyField(source='user.username')
|
||||
|
||||
class Meta:
|
||||
model = Rating
|
||||
fields = ['id', 'product', 'user', 'username', 'rating', 'comment', 'created_at']
|
||||
read_only_fields = ['id', 'created_at', 'username']
|
||||
|
||||
|
||||
class ProductSerializer(serializers.ModelSerializer):
|
||||
category_name = serializers.ReadOnlyField(source='category.name')
|
||||
average_rating = serializers.SerializerMethodField()
|
||||
|
||||
class Meta:
|
||||
model = Product
|
||||
fields = ['id', 'name', 'description', 'price', 'image', 'category', 'stock','color','size',
|
||||
'category_name', 'average_rating', 'created_at']
|
||||
read_only_fields = ['id', 'created_at', 'category_name', 'average_rating']
|
||||
|
||||
def get_average_rating(self, obj):
|
||||
ratings = obj.ratings.all()
|
||||
if ratings:
|
||||
return sum(rating.rating for rating in ratings) / len(ratings)
|
||||
return 0
|
||||
|
||||
|
||||
class ProductDetailSerializer(ProductSerializer):
|
||||
ratings = RatingSerializer(many=True, read_only=True)
|
||||
|
||||
class Meta(ProductSerializer.Meta):
|
||||
fields = ProductSerializer.Meta.fields + ['ratings']
|
||||
|
||||
|
||||
class OrderItemSerializer(serializers.ModelSerializer):
|
||||
product_name = serializers.ReadOnlyField(source='product.name')
|
||||
product_image = serializers.ImageField(source='product.image', read_only=True)
|
||||
subtotal = serializers.SerializerMethodField()
|
||||
|
||||
class Meta:
|
||||
model = OrderItem
|
||||
fields = ['id', 'product', 'product_name', 'product_image', 'quantity', 'price', 'subtotal']
|
||||
read_only_fields = ['id', 'product_name', 'product_image', 'subtotal']
|
||||
|
||||
def get_subtotal(self, obj):
|
||||
return obj.get_subtotal()
|
||||
|
||||
|
||||
class OrderItemCreateSerializer(serializers.ModelSerializer):
|
||||
class Meta:
|
||||
model = OrderItem
|
||||
fields = ['product', 'quantity']
|
||||
|
||||
|
||||
class OrderSerializer(serializers.ModelSerializer):
|
||||
user_name = serializers.ReadOnlyField(source='user.get_full_name')
|
||||
order_items = OrderItemSerializer(many=True, read_only=True)
|
||||
items = OrderItemCreateSerializer(many=True, write_only=True, required=False)
|
||||
|
||||
class Meta:
|
||||
model = Order
|
||||
fields = ['id', 'user', 'user_name', 'total_price', 'status', 'shipping_address',
|
||||
'created_at', 'order_items', 'items']
|
||||
read_only_fields = ['id', 'created_at', 'user_name', 'total_price', 'order_items']
|
||||
|
||||
def create(self, validated_data):
|
||||
items_data = validated_data.pop('items', [])
|
||||
order = Order.objects.create(**validated_data)
|
||||
|
||||
# Create order items if provided
|
||||
for item_data in items_data:
|
||||
product = item_data.get('product')
|
||||
quantity = item_data.get('quantity', 1)
|
||||
order.add_product(product, quantity)
|
||||
|
||||
return order
|
||||
|
||||
def update(self, instance, validated_data):
|
||||
items_data = validated_data.pop('items', [])
|
||||
|
||||
# Update the order fields
|
||||
for attr, value in validated_data.items():
|
||||
setattr(instance, attr, value)
|
||||
instance.save()
|
||||
|
||||
# Add new items if provided
|
||||
for item_data in items_data:
|
||||
product = item_data.get('product')
|
||||
quantity = item_data.get('quantity', 1)
|
||||
instance.add_product(product, quantity)
|
||||
|
||||
return instance
|
||||
|
||||
|
||||
class CartItemSerializer(serializers.ModelSerializer):
|
||||
product_name = serializers.CharField(source='product.name', read_only=True)
|
||||
product_price = serializers.SerializerMethodField()
|
||||
product_image = serializers.SerializerMethodField()
|
||||
subtotal = serializers.SerializerMethodField()
|
||||
|
||||
class Meta:
|
||||
model = CartItem
|
||||
fields = ['id', 'product', 'product_name', 'product_price', 'product_image', 'quantity', 'subtotal', 'created_at', 'updated_at']
|
||||
read_only_fields = ['created_at', 'updated_at']
|
||||
|
||||
def get_subtotal(self, obj):
|
||||
try:
|
||||
return float(obj.product.price * obj.quantity)
|
||||
except (AttributeError, TypeError):
|
||||
return 0.0
|
||||
|
||||
def get_product_price(self, obj):
|
||||
try:
|
||||
return float(obj.product.price)
|
||||
except (AttributeError, TypeError):
|
||||
return 0.0
|
||||
|
||||
def get_product_image(self, obj):
|
||||
if obj.product and obj.product.image:
|
||||
request = self.context.get('request')
|
||||
if request is not None:
|
||||
return request.build_absolute_uri(obj.product.image.url)
|
||||
return obj.product.image.url
|
||||
return None
|
||||
|
||||
|
||||
class CartSerializer(serializers.ModelSerializer):
|
||||
items = CartItemSerializer(many=True, read_only=True)
|
||||
total = serializers.SerializerMethodField()
|
||||
|
||||
class Meta:
|
||||
model = Cart
|
||||
fields = ['id', 'user', 'items', 'total', 'created_at', 'updated_at']
|
||||
read_only_fields = ['created_at', 'updated_at']
|
||||
|
||||
def get_total(self, obj):
|
||||
return obj.get_total()
|
||||
|
||||
|
||||
class FavoriteSerializer(serializers.ModelSerializer):
|
||||
product = ProductSerializer(read_only=True)
|
||||
|
||||
class Meta:
|
||||
model = Favorite
|
||||
fields = ['id', 'product', 'created_at']
|
||||
read_only_fields = ['id', 'created_at']
|
||||
@@ -0,0 +1,3 @@
|
||||
from django.test import TestCase
|
||||
|
||||
# Create your tests here.
|
||||
@@ -0,0 +1,35 @@
|
||||
from django.urls import path, include
|
||||
from rest_framework.routers import DefaultRouter
|
||||
from . import views
|
||||
from .carts import CartViewSet
|
||||
from .auth import CustomAuthToken, LogoutView
|
||||
from .views import (
|
||||
UserViewSet, CategoryViewSet, ProductViewSet, RatingViewSet,
|
||||
OrderViewSet, OrderItemViewSet, get_csrf_token, serve_protected_media,
|
||||
FavoriteViewSet
|
||||
)
|
||||
|
||||
router = DefaultRouter()
|
||||
router.register(r'users', UserViewSet)
|
||||
router.register(r'categories', CategoryViewSet)
|
||||
router.register(r'products', ProductViewSet)
|
||||
router.register(r'ratings', RatingViewSet)
|
||||
router.register(r'orders', OrderViewSet)
|
||||
router.register(r'order-items', OrderItemViewSet)
|
||||
router.register(r'favorites', FavoriteViewSet, basename='favorite')
|
||||
|
||||
# Cart endpoints
|
||||
cart_router = DefaultRouter()
|
||||
cart_router.register(r'cart', CartViewSet, basename='cart')
|
||||
|
||||
urlpatterns = [
|
||||
path('', include(router.urls)),
|
||||
path('', include(cart_router.urls)),
|
||||
path('auth/', include('rest_framework.urls', namespace='rest_framework')),
|
||||
|
||||
# Token authentication endpoints
|
||||
path('get-csrf-token/', get_csrf_token, name='get-csrf-token'),
|
||||
path('token-auth/', CustomAuthToken.as_view(), name='token_auth'),
|
||||
path('logout/', LogoutView.as_view(), name='logout'),
|
||||
path('media/<path:path>', serve_protected_media, name='serve_protected_media'),
|
||||
]
|
||||
@@ -0,0 +1,282 @@
|
||||
from django.conf import settings
|
||||
from rest_framework import viewsets, status, filters
|
||||
from rest_framework.decorators import action
|
||||
from rest_framework.response import Response
|
||||
from rest_framework.permissions import IsAuthenticated, IsAdminUser, AllowAny
|
||||
from django.db.models import Avg
|
||||
from django.shortcuts import get_object_or_404
|
||||
from django.http import HttpResponseForbidden, JsonResponse
|
||||
from django.views.decorators.csrf import ensure_csrf_cookie
|
||||
from django.middleware.csrf import get_token
|
||||
from rest_framework.exceptions import PermissionDenied
|
||||
from django.conf import settings
|
||||
from django.http import FileResponse, HttpResponseForbidden
|
||||
from django.views.decorators.http import require_GET
|
||||
from rest_framework.authentication import TokenAuthentication
|
||||
from rest_framework.decorators import authentication_classes, permission_classes
|
||||
from rest_framework.permissions import IsAuthenticated
|
||||
import os
|
||||
from .models import User, Category, Product, Rating, Order, OrderItem, Favorite
|
||||
from .serializers import (
|
||||
UserSerializer, CategorySerializer, ProductSerializer, ProductDetailSerializer,
|
||||
RatingSerializer, OrderSerializer, OrderItemSerializer, FavoriteSerializer
|
||||
)
|
||||
|
||||
class UserViewSet(viewsets.ModelViewSet):
|
||||
queryset = User.objects.all()
|
||||
serializer_class = UserSerializer
|
||||
filter_backends = [filters.SearchFilter]
|
||||
search_fields = ['username', 'email', 'first_name', 'last_name']
|
||||
permission_classes = [AllowAny]
|
||||
|
||||
def get_queryset(self):
|
||||
# If user_id query param is provided, filter by that
|
||||
user_id = self.request.query_params.get('user_id', None)
|
||||
if user_id:
|
||||
return User.objects.filter(id=user_id)
|
||||
|
||||
# If no specific user_id is requested, and user is staff, show all
|
||||
if self.request.user.is_authenticated and self.request.user.is_staff:
|
||||
return User.objects.all()
|
||||
|
||||
# For anonymous or non-staff users requesting the list endpoint, return empty queryset
|
||||
if self.action == 'list':
|
||||
return User.objects.none()
|
||||
|
||||
# For other actions like retrieve, let Django's permission system handle it
|
||||
return User.objects.all()
|
||||
|
||||
@action(detail=False, methods=['get'])
|
||||
def me(self, request):
|
||||
"""Get current user's profile"""
|
||||
if not request.user.is_authenticated:
|
||||
return Response({'error': 'Authentication required'}, status=status.HTTP_401_UNAUTHORIZED)
|
||||
|
||||
serializer = self.get_serializer(request.user)
|
||||
return Response(serializer.data)
|
||||
|
||||
|
||||
class CategoryViewSet(viewsets.ModelViewSet):
|
||||
queryset = Category.objects.all()
|
||||
serializer_class = CategorySerializer
|
||||
filter_backends = [filters.SearchFilter]
|
||||
search_fields = ['name']
|
||||
permission_classes = [AllowAny]
|
||||
|
||||
def get_permissions(self):
|
||||
if self.action in ['create', 'update', 'partial_update', 'destroy']:
|
||||
permission_classes = [IsAdminUser]
|
||||
else:
|
||||
permission_classes = [AllowAny]
|
||||
return [permission() for permission in permission_classes]
|
||||
|
||||
@action(detail=True, methods=['get'])
|
||||
def products(self, request, pk=None):
|
||||
category = self.get_object()
|
||||
products = Product.objects.filter(category=category)
|
||||
serializer = ProductSerializer(products, many=True)
|
||||
return Response(serializer.data)
|
||||
|
||||
|
||||
class ProductViewSet(viewsets.ModelViewSet):
|
||||
queryset = Product.objects.all()
|
||||
serializer_class = ProductSerializer
|
||||
filter_backends = [filters.SearchFilter, filters.OrderingFilter]
|
||||
search_fields = ['name', 'description', 'category__name']
|
||||
ordering_fields = ['name', 'price', 'created_at']
|
||||
permission_classes = [AllowAny]
|
||||
|
||||
def get_permissions(self):
|
||||
if self.action in ['create', 'update', 'partial_update', 'destroy']:
|
||||
permission_classes = [IsAdminUser]
|
||||
else:
|
||||
permission_classes = [AllowAny]
|
||||
return [permission() for permission in permission_classes]
|
||||
|
||||
def get_serializer_class(self):
|
||||
if self.action == 'retrieve':
|
||||
return ProductDetailSerializer
|
||||
return ProductSerializer
|
||||
|
||||
@action(detail=True, methods=['post'])
|
||||
def rate(self, request, pk=None):
|
||||
# Still require authentication for rating
|
||||
if not request.user.is_authenticated:
|
||||
return Response({'error': 'Authentication required'}, status=status.HTTP_401_UNAUTHORIZED)
|
||||
|
||||
product = self.get_object()
|
||||
rating_value = request.data.get('rating')
|
||||
comment = request.data.get('comment', '')
|
||||
|
||||
if not rating_value:
|
||||
return Response({'error': 'Rating is required'}, status=status.HTTP_400_BAD_REQUEST)
|
||||
|
||||
# Update or create rating
|
||||
rating, created = Rating.objects.update_or_create(
|
||||
product=product,
|
||||
user=request.user,
|
||||
defaults={'rating': rating_value, 'comment': comment}
|
||||
)
|
||||
|
||||
serializer = RatingSerializer(rating)
|
||||
return Response(serializer.data)
|
||||
|
||||
|
||||
class RatingViewSet(viewsets.ModelViewSet):
|
||||
queryset = Rating.objects.all()
|
||||
serializer_class = RatingSerializer
|
||||
permission_classes = [AllowAny]
|
||||
|
||||
def get_permissions(self):
|
||||
if self.action in ['update', 'partial_update', 'destroy']:
|
||||
permission_classes = [IsAuthenticated]
|
||||
else:
|
||||
permission_classes = [AllowAny]
|
||||
return [permission() for permission in permission_classes]
|
||||
|
||||
def perform_create(self, serializer):
|
||||
# Still require authentication for creating ratings
|
||||
if not self.request.user.is_authenticated:
|
||||
raise PermissionDenied('Authentication required to create ratings')
|
||||
serializer.save(user=self.request.user)
|
||||
|
||||
|
||||
class OrderViewSet(viewsets.ModelViewSet):
|
||||
queryset = Order.objects.all()
|
||||
serializer_class = OrderSerializer
|
||||
filter_backends = [filters.OrderingFilter]
|
||||
ordering_fields = ['created_at', 'status']
|
||||
permission_classes = [AllowAny]
|
||||
|
||||
def get_queryset(self):
|
||||
user_id = self.request.query_params.get('user_id', None)
|
||||
if user_id:
|
||||
return Order.objects.filter(user_id=user_id)
|
||||
|
||||
if self.request.user.is_authenticated:
|
||||
if self.request.user.is_staff:
|
||||
return Order.objects.all()
|
||||
return Order.objects.filter(user=self.request.user)
|
||||
|
||||
# For anonymous users, return empty queryset
|
||||
return Order.objects.none()
|
||||
|
||||
def perform_create(self, serializer):
|
||||
# For creating orders, require authentication
|
||||
if not self.request.user.is_authenticated:
|
||||
raise PermissionDenied('Authentication required to create orders')
|
||||
serializer.save(user=self.request.user)
|
||||
|
||||
@action(detail=True, methods=['post'])
|
||||
def cancel(self, request, pk=None):
|
||||
order = self.get_object()
|
||||
|
||||
# Check if order belongs to current user or user is admin
|
||||
if self.request.user.is_authenticated and (order.user.id == request.user.id or request.user.is_staff):
|
||||
# Check if order can be canceled
|
||||
if order.status not in ['Pending', 'Shipped']:
|
||||
return Response({'error': 'Cannot cancel order in current status'},
|
||||
status=status.HTTP_400_BAD_REQUEST)
|
||||
|
||||
order.status = 'Cancelled'
|
||||
order.save()
|
||||
serializer = OrderSerializer(order)
|
||||
return Response(serializer.data)
|
||||
else:
|
||||
return Response({'error': 'Not authorized'}, status=status.HTTP_403_FORBIDDEN)
|
||||
|
||||
|
||||
class OrderItemViewSet(viewsets.ModelViewSet):
|
||||
queryset = OrderItem.objects.all()
|
||||
serializer_class = OrderItemSerializer
|
||||
permission_classes = [AllowAny]
|
||||
|
||||
def get_queryset(self):
|
||||
user_id = self.request.query_params.get('user_id', None)
|
||||
if user_id:
|
||||
return OrderItem.objects.filter(order__user_id=user_id)
|
||||
|
||||
if self.request.user.is_authenticated:
|
||||
if self.request.user.is_staff:
|
||||
return OrderItem.objects.all()
|
||||
return OrderItem.objects.filter(order__user=self.request.user)
|
||||
|
||||
# For anonymous users, return empty queryset
|
||||
return OrderItem.objects.none()
|
||||
|
||||
def get_csrf_token(request):
|
||||
"""
|
||||
This view sets the CSRF cookie and returns the token in the response.
|
||||
The client can then use this token for subsequent requests.
|
||||
"""
|
||||
token = get_token(request)
|
||||
return JsonResponse({'csrfToken': token})
|
||||
@require_GET
|
||||
@authentication_classes([TokenAuthentication])
|
||||
@permission_classes([IsAuthenticated])
|
||||
def serve_protected_media(request, path):
|
||||
"""
|
||||
Serve media files with authentication check.
|
||||
The path parameter should be the relative path within MEDIA_ROOT.
|
||||
"""
|
||||
# Construct the full path
|
||||
file_path = os.path.join(settings.MEDIA_ROOT, path)
|
||||
|
||||
# Basic security check to prevent directory traversal
|
||||
if not os.path.abspath(file_path).startswith(os.path.abspath(settings.MEDIA_ROOT)):
|
||||
return HttpResponseForbidden('Invalid path')
|
||||
|
||||
# Check if file exists
|
||||
if not os.path.exists(file_path):
|
||||
return HttpResponseForbidden('File not found')
|
||||
|
||||
# Serve the file
|
||||
return FileResponse(open(file_path, 'rb'))
|
||||
|
||||
class FavoriteViewSet(viewsets.ViewSet):
|
||||
permission_classes = [IsAuthenticated]
|
||||
|
||||
def list(self, request):
|
||||
"""Get all favorites for the current user"""
|
||||
favorites = Favorite.objects.filter(user=request.user)
|
||||
serializer = FavoriteSerializer(favorites, many=True, context={'request': request})
|
||||
return Response(serializer.data)
|
||||
|
||||
@action(detail=False, methods=['post'])
|
||||
def toggle(self, request):
|
||||
"""Toggle favorite status for a product"""
|
||||
product_id = request.data.get('product_id')
|
||||
if not product_id:
|
||||
return Response({'error': 'Product ID is required'}, status=status.HTTP_400_BAD_REQUEST)
|
||||
|
||||
try:
|
||||
product = Product.objects.get(id=product_id)
|
||||
except Product.DoesNotExist:
|
||||
return Response({'error': 'Product not found'}, status=status.HTTP_404_NOT_FOUND)
|
||||
|
||||
# Check if favorite exists
|
||||
favorite = Favorite.objects.filter(user=request.user, product=product).first()
|
||||
|
||||
if favorite:
|
||||
# Remove from favorites
|
||||
favorite.delete()
|
||||
return Response({'message': 'Product removed from favorites'})
|
||||
else:
|
||||
# Add to favorites
|
||||
Favorite.objects.create(user=request.user, product=product)
|
||||
return Response({'message': 'Product added to favorites'})
|
||||
|
||||
@action(detail=False, methods=['get'])
|
||||
def check(self, request):
|
||||
"""Check if a product is favorited"""
|
||||
product_id = request.query_params.get('product_id')
|
||||
if not product_id:
|
||||
return Response({'error': 'Product ID is required'}, status=status.HTTP_400_BAD_REQUEST)
|
||||
|
||||
try:
|
||||
product = Product.objects.get(id=product_id)
|
||||
except Product.DoesNotExist:
|
||||
return Response({'error': 'Product not found'}, status=status.HTTP_404_NOT_FOUND)
|
||||
|
||||
is_favorited = Favorite.objects.filter(user=request.user, product=product).exists()
|
||||
return Response({'is_favorited': is_favorited})
|
||||
@@ -0,0 +1,6 @@
|
||||
def main():
|
||||
print("Hello from backend!")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
@@ -0,0 +1,22 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Django's command-line utility for administrative tasks."""
|
||||
import os
|
||||
import sys
|
||||
|
||||
|
||||
def main():
|
||||
"""Run administrative tasks."""
|
||||
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'shoppingApp.settings')
|
||||
try:
|
||||
from django.core.management import execute_from_command_line
|
||||
except ImportError as exc:
|
||||
raise ImportError(
|
||||
"Couldn't import Django. Are you sure it's installed and "
|
||||
"available on your PYTHONPATH environment variable? Did you "
|
||||
"forget to activate a virtual environment?"
|
||||
) from exc
|
||||
execute_from_command_line(sys.argv)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
@@ -0,0 +1,13 @@
|
||||
[project]
|
||||
name = "backend"
|
||||
version = "0.1.0"
|
||||
description = "Add your description here"
|
||||
readme = "README.md"
|
||||
requires-python = ">=3.13"
|
||||
dependencies = [
|
||||
"django>=5.2",
|
||||
"django-jazzmin>=3.0.1",
|
||||
"django-rest-framework>=0.1.0",
|
||||
"djangorestframework>=3.16.0",
|
||||
"pillow>=11.2.1",
|
||||
]
|
||||
@@ -0,0 +1,7 @@
|
||||
asgiref==3.8.1
|
||||
django==5.2
|
||||
django-jazzmin==3.0.1
|
||||
django-rest-framework==0.1.0
|
||||
djangorestframework==3.16.0
|
||||
pillow==11.2.1
|
||||
sqlparse==0.5.3
|
||||
Whitespace-only changes.
@@ -0,0 +1,16 @@
|
||||
"""
|
||||
ASGI config for shoppingApp project.
|
||||
|
||||
It exposes the ASGI callable as a module-level variable named ``application``.
|
||||
|
||||
For more information on this file, see
|
||||
https://docs.djangoproject.com/en/4.2/howto/deployment/asgi/
|
||||
"""
|
||||
|
||||
import os
|
||||
|
||||
from django.core.asgi import get_asgi_application
|
||||
|
||||
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'shoppingApp.settings')
|
||||
|
||||
application = get_asgi_application()
|
||||
@@ -0,0 +1,177 @@
|
||||
"""
|
||||
Django settings for shoppingApp project.
|
||||
|
||||
Generated by 'django-admin startproject' using Django 4.2.20.
|
||||
|
||||
For more information on this file, see
|
||||
https://docs.djangoproject.com/en/4.2/topics/settings/
|
||||
|
||||
For the full list of settings and their values, see
|
||||
https://docs.djangoproject.com/en/4.2/ref/settings/
|
||||
"""
|
||||
|
||||
from pathlib import Path
|
||||
import os
|
||||
# Build paths inside the project like this: BASE_DIR / 'subdir'.
|
||||
BASE_DIR = Path(__file__).resolve().parent.parent
|
||||
|
||||
|
||||
# Quick-start development settings - unsuitable for production
|
||||
# See https://docs.djangoproject.com/en/4.2/howto/deployment/checklist/
|
||||
|
||||
# SECURITY WARNING: keep the secret key used in production secret!
|
||||
SECRET_KEY = 'django-insecure-xqasrzhtay$_d+mae!w!zon^@ebx3czh7t-#+_j1g@%ui6na4)'
|
||||
|
||||
# SECURITY WARNING: don't run with debug turned on in production!
|
||||
DEBUG = True
|
||||
|
||||
ALLOWED_HOSTS = ['*']
|
||||
|
||||
|
||||
# Application definition
|
||||
|
||||
INSTALLED_APPS = [
|
||||
'jazzmin',
|
||||
'app',
|
||||
'django.contrib.admin',
|
||||
'django.contrib.auth',
|
||||
'django.contrib.contenttypes',
|
||||
'django.contrib.sessions',
|
||||
'django.contrib.messages',
|
||||
'django.contrib.staticfiles',
|
||||
'rest_framework',
|
||||
'rest_framework.authtoken',
|
||||
'corsheaders',
|
||||
]
|
||||
|
||||
MIDDLEWARE = [
|
||||
'django.middleware.security.SecurityMiddleware',
|
||||
'django.contrib.sessions.middleware.SessionMiddleware',
|
||||
'django.middleware.common.CommonMiddleware',
|
||||
'django.middleware.csrf.CsrfViewMiddleware',
|
||||
'django.contrib.auth.middleware.AuthenticationMiddleware',
|
||||
'django.contrib.messages.middleware.MessageMiddleware',
|
||||
'django.middleware.clickjacking.XFrameOptionsMiddleware',
|
||||
]
|
||||
REST_FRAMEWORK = {
|
||||
'DEFAULT_PERMISSION_CLASSES' : ['rest_framework.permissions.AllowAny'],
|
||||
'DEFAULT_AUTHENTICATION_CLASSES': [
|
||||
'rest_framework.authentication.TokenAuthentication',
|
||||
],
|
||||
}
|
||||
|
||||
ROOT_URLCONF = 'shoppingApp.urls'
|
||||
|
||||
TEMPLATES = [
|
||||
{
|
||||
'BACKEND': 'django.template.backends.django.DjangoTemplates',
|
||||
'DIRS': [],
|
||||
'APP_DIRS': True,
|
||||
'OPTIONS': {
|
||||
'context_processors': [
|
||||
'django.template.context_processors.debug',
|
||||
'django.template.context_processors.request',
|
||||
'django.contrib.auth.context_processors.auth',
|
||||
'django.contrib.messages.context_processors.messages',
|
||||
],
|
||||
},
|
||||
},
|
||||
]
|
||||
|
||||
# CORS settings
|
||||
CORS_ORIGIN_ALLOW_ALL = True
|
||||
CORS_ALLOW_ALL_ORIGINS = True
|
||||
CORS_ALLOW_CREDENTIALS = True
|
||||
|
||||
CORS_ALLOWED_ORIGINS = [
|
||||
'http://192.168.1.75:8081',
|
||||
'http://192.168.1.56:8081',
|
||||
]
|
||||
WSGI_APPLICATION = 'shoppingApp.wsgi.application'
|
||||
|
||||
|
||||
# Database
|
||||
# https://docs.djangoproject.com/en/4.2/ref/settings/#databases
|
||||
|
||||
DATABASES = {
|
||||
'default': {
|
||||
'ENGINE': 'django.db.backends.sqlite3',
|
||||
'NAME': BASE_DIR / 'db.sqlite3',
|
||||
}
|
||||
}
|
||||
AUTH_USER_MODEL = 'app.User'
|
||||
|
||||
# Password validation
|
||||
# https://docs.djangoproject.com/en/4.2/ref/settings/#auth-password-validators
|
||||
|
||||
AUTH_PASSWORD_VALIDATORS = [
|
||||
{
|
||||
'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
|
||||
},
|
||||
{
|
||||
'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
|
||||
},
|
||||
{
|
||||
'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
|
||||
},
|
||||
{
|
||||
'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
|
||||
},
|
||||
]
|
||||
|
||||
|
||||
# Internationalization
|
||||
# https://docs.djangoproject.com/en/4.2/topics/i18n/
|
||||
|
||||
LANGUAGE_CODE = 'en-us'
|
||||
|
||||
TIME_ZONE = 'UTC'
|
||||
|
||||
USE_I18N = True
|
||||
|
||||
USE_TZ = True
|
||||
|
||||
|
||||
# Static files (CSS, JavaScript, Images)
|
||||
# https://docs.djangoproject.com/en/4.2/howto/static-files/
|
||||
|
||||
STATIC_URL = 'static/'
|
||||
STATIC_ROOT = os.path.join(BASE_DIR, "static")
|
||||
# STATICFILES_DIRS = [
|
||||
# BASE_DIR / 'static',
|
||||
# ]
|
||||
|
||||
|
||||
# Default primary key field type
|
||||
# https://docs.djangoproject.com/en/4.2/ref/settings/#default-auto-field
|
||||
|
||||
DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'
|
||||
MEDIA_URL = '/media/'
|
||||
MEDIA_ROOT = os.path.join(BASE_DIR, 'media')
|
||||
|
||||
customColorPalette = [
|
||||
{
|
||||
'color': 'hsl(4, 90%, 58%)',
|
||||
'label': 'Red'
|
||||
},
|
||||
{
|
||||
'color': 'hsl(340, 82%, 52%)',
|
||||
'label': 'Pink'
|
||||
},
|
||||
{
|
||||
'color': 'hsl(291, 64%, 42%)',
|
||||
'label': 'Purple'
|
||||
},
|
||||
{
|
||||
'color': 'hsl(262, 52%, 47%)',
|
||||
'label': 'Deep Purple'
|
||||
},
|
||||
{
|
||||
'color': 'hsl(231, 48%, 48%)',
|
||||
'label': 'Indigo'
|
||||
},
|
||||
{
|
||||
'color': 'hsl(207, 90%, 54%)',
|
||||
'label': 'Blue'
|
||||
},
|
||||
]
|
||||
@@ -0,0 +1,29 @@
|
||||
"""
|
||||
URL configuration for shoppingApp project.
|
||||
|
||||
The `urlpatterns` list routes URLs to views. For more information please see:
|
||||
https://docs.djangoproject.com/en/4.2/topics/http/urls/
|
||||
Examples:
|
||||
Function views
|
||||
1. Add an import: from my_app import views
|
||||
2. Add a URL to urlpatterns: path('', views.home, name='home')
|
||||
Class-based views
|
||||
1. Add an import: from other_app.views import Home
|
||||
2. Add a URL to urlpatterns: path('', Home.as_view(), name='home')
|
||||
Including another URLconf
|
||||
1. Import the include() function: from django.urls import include, path
|
||||
2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
|
||||
"""
|
||||
from django.contrib import admin
|
||||
from django.urls import path, include
|
||||
from django.conf import settings
|
||||
from shoppingApp.settings import MEDIA_ROOT, MEDIA_URL
|
||||
from django.conf.urls.static import static
|
||||
|
||||
urlpatterns = [
|
||||
path('api/', include('app.urls')),
|
||||
# path('', admin.site.urls),
|
||||
]
|
||||
|
||||
urlpatterns += static(MEDIA_URL, document_root=MEDIA_ROOT)
|
||||
urlpatterns.append(path('', admin.site.urls, name='admin'))
|
||||
@@ -0,0 +1,16 @@
|
||||
"""
|
||||
WSGI config for shoppingApp project.
|
||||
|
||||
It exposes the WSGI callable as a module-level variable named ``application``.
|
||||
|
||||
For more information on this file, see
|
||||
https://docs.djangoproject.com/en/4.2/howto/deployment/wsgi/
|
||||
"""
|
||||
|
||||
import os
|
||||
|
||||
from django.core.wsgi import get_wsgi_application
|
||||
|
||||
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'shoppingApp.settings')
|
||||
|
||||
application = get_wsgi_application()
|
||||
Generated
+128
@@ -0,0 +1,128 @@
|
||||
version = 1
|
||||
revision = 1
|
||||
requires-python = ">=3.13"
|
||||
|
||||
[[package]]
|
||||
name = "asgiref"
|
||||
version = "3.8.1"
|
||||
source = { registry = "https://pypi.org/simple" }
|
||||
sdist = { url = "https://files.pythonhosted.org/packages/29/38/b3395cc9ad1b56d2ddac9970bc8f4141312dbaec28bc7c218b0dfafd0f42/asgiref-3.8.1.tar.gz", hash = "sha256:c343bd80a0bec947a9860adb4c432ffa7db769836c64238fc34bdc3fec84d590", size = 35186 }
|
||||
wheels = [
|
||||
{ url = "https://files.pythonhosted.org/packages/39/e3/893e8757be2612e6c266d9bb58ad2e3651524b5b40cf56761e985a28b13e/asgiref-3.8.1-py3-none-any.whl", hash = "sha256:3e1e3ecc849832fe52ccf2cb6686b7a55f82bb1d6aee72a58826471390335e47", size = 23828 },
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "backend"
|
||||
version = "0.1.0"
|
||||
source = { virtual = "." }
|
||||
dependencies = [
|
||||
{ name = "django" },
|
||||
{ name = "django-jazzmin" },
|
||||
{ name = "django-rest-framework" },
|
||||
{ name = "djangorestframework" },
|
||||
{ name = "pillow" },
|
||||
]
|
||||
|
||||
[package.metadata]
|
||||
requires-dist = [
|
||||
{ name = "django", specifier = ">=5.2" },
|
||||
{ name = "django-jazzmin", specifier = ">=3.0.1" },
|
||||
{ name = "django-rest-framework", specifier = ">=0.1.0" },
|
||||
{ name = "djangorestframework", specifier = ">=3.16.0" },
|
||||
{ name = "pillow", specifier = ">=11.2.1" },
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "django"
|
||||
version = "5.2"
|
||||
source = { registry = "https://pypi.org/simple" }
|
||||
dependencies = [
|
||||
{ name = "asgiref" },
|
||||
{ name = "sqlparse" },
|
||||
{ name = "tzdata", marker = "sys_platform == 'win32'" },
|
||||
]
|
||||
sdist = { url = "https://files.pythonhosted.org/packages/4c/1b/c6da718c65228eb3a7ff7ba6a32d8e80fa840ca9057490504e099e4dd1ef/Django-5.2.tar.gz", hash = "sha256:1a47f7a7a3d43ce64570d350e008d2949abe8c7e21737b351b6a1611277c6d89", size = 10824891 }
|
||||
wheels = [
|
||||
{ url = "https://files.pythonhosted.org/packages/63/e0/6a5b5ea350c5bd63fe94b05e4c146c18facb51229d9dee42aa39f9fc2214/Django-5.2-py3-none-any.whl", hash = "sha256:91ceed4e3a6db5aedced65e3c8f963118ea9ba753fc620831c77074e620e7d83", size = 8301361 },
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "django-jazzmin"
|
||||
version = "3.0.1"
|
||||
source = { registry = "https://pypi.org/simple" }
|
||||
dependencies = [
|
||||
{ name = "django" },
|
||||
]
|
||||
sdist = { url = "https://files.pythonhosted.org/packages/84/96/21b6255e90d92a3eb4e93bea9376635d54258e0353ebb913a55e40ae9254/django_jazzmin-3.0.1.tar.gz", hash = "sha256:67ae148bade41267a09ca8e4352ddefa6121795ebbac238bb9a6564ff841eb1b", size = 2053550 }
|
||||
wheels = [
|
||||
{ url = "https://files.pythonhosted.org/packages/ad/5b/2f8c4b168e6c41bf1e4b14d787deb23d80f618f0693db913bbe208a4a907/django_jazzmin-3.0.1-py3-none-any.whl", hash = "sha256:12a0a4c1d4fd09c2eef22acf6a1f03112b515ba695c59faa8ea80efc81c1f21b", size = 2125957 },
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "django-rest-framework"
|
||||
version = "0.1.0"
|
||||
source = { registry = "https://pypi.org/simple" }
|
||||
dependencies = [
|
||||
{ name = "djangorestframework" },
|
||||
]
|
||||
sdist = { url = "https://files.pythonhosted.org/packages/ed/d2/61159bc6efd1bf16adc4a2a48f7ace2080d1f7aef054f606d1857cab490c/django-rest-framework-0.1.0.tar.gz", hash = "sha256:47a8f496fa69e3b6bd79f68dd7a1527d907d6b77f009e9db7cf9bb21cc565e4a", size = 969 }
|
||||
|
||||
[[package]]
|
||||
name = "djangorestframework"
|
||||
version = "3.16.0"
|
||||
source = { registry = "https://pypi.org/simple" }
|
||||
dependencies = [
|
||||
{ name = "django" },
|
||||
]
|
||||
sdist = { url = "https://files.pythonhosted.org/packages/7d/97/112c5a72e6917949b6d8a18ad6c6e72c46da4290c8f36ee5f1c1dcbc9901/djangorestframework-3.16.0.tar.gz", hash = "sha256:f022ff46613584de994c0c6a4aebbace5fd700555fbe9d33b865ebf173eba6c9", size = 1068408 }
|
||||
wheels = [
|
||||
{ url = "https://files.pythonhosted.org/packages/eb/3e/2448e93f4f87fc9a9f35e73e3c05669e0edd0c2526834686e949bb1fd303/djangorestframework-3.16.0-py3-none-any.whl", hash = "sha256:bea7e9f6b96a8584c5224bfb2e4348dfb3f8b5e34edbecb98da258e892089361", size = 1067305 },
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "pillow"
|
||||
version = "11.2.1"
|
||||
source = { registry = "https://pypi.org/simple" }
|
||||
sdist = { url = "https://files.pythonhosted.org/packages/af/cb/bb5c01fcd2a69335b86c22142b2bccfc3464087efb7fd382eee5ffc7fdf7/pillow-11.2.1.tar.gz", hash = "sha256:a64dd61998416367b7ef979b73d3a85853ba9bec4c2925f74e588879a58716b6", size = 47026707 }
|
||||
wheels = [
|
||||
{ url = "https://files.pythonhosted.org/packages/36/9c/447528ee3776e7ab8897fe33697a7ff3f0475bb490c5ac1456a03dc57956/pillow-11.2.1-cp313-cp313-macosx_10_13_x86_64.whl", hash = "sha256:fdec757fea0b793056419bca3e9932eb2b0ceec90ef4813ea4c1e072c389eb28", size = 3190098 },
|
||||
{ url = "https://files.pythonhosted.org/packages/b5/09/29d5cd052f7566a63e5b506fac9c60526e9ecc553825551333e1e18a4858/pillow-11.2.1-cp313-cp313-macosx_11_0_arm64.whl", hash = "sha256:b0e130705d568e2f43a17bcbe74d90958e8a16263868a12c3e0d9c8162690830", size = 3030166 },
|
||||
{ url = "https://files.pythonhosted.org/packages/71/5d/446ee132ad35e7600652133f9c2840b4799bbd8e4adba881284860da0a36/pillow-11.2.1-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:7bdb5e09068332578214cadd9c05e3d64d99e0e87591be22a324bdbc18925be0", size = 4408674 },
|
||||
{ url = "https://files.pythonhosted.org/packages/69/5f/cbe509c0ddf91cc3a03bbacf40e5c2339c4912d16458fcb797bb47bcb269/pillow-11.2.1-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:d189ba1bebfbc0c0e529159631ec72bb9e9bc041f01ec6d3233d6d82eb823bc1", size = 4496005 },
|
||||
{ url = "https://files.pythonhosted.org/packages/f9/b3/dd4338d8fb8a5f312021f2977fb8198a1184893f9b00b02b75d565c33b51/pillow-11.2.1-cp313-cp313-manylinux_2_28_aarch64.whl", hash = "sha256:191955c55d8a712fab8934a42bfefbf99dd0b5875078240943f913bb66d46d9f", size = 4518707 },
|
||||
{ url = "https://files.pythonhosted.org/packages/13/eb/2552ecebc0b887f539111c2cd241f538b8ff5891b8903dfe672e997529be/pillow-11.2.1-cp313-cp313-manylinux_2_28_x86_64.whl", hash = "sha256:ad275964d52e2243430472fc5d2c2334b4fc3ff9c16cb0a19254e25efa03a155", size = 4610008 },
|
||||
{ url = "https://files.pythonhosted.org/packages/72/d1/924ce51bea494cb6e7959522d69d7b1c7e74f6821d84c63c3dc430cbbf3b/pillow-11.2.1-cp313-cp313-musllinux_1_2_aarch64.whl", hash = "sha256:750f96efe0597382660d8b53e90dd1dd44568a8edb51cb7f9d5d918b80d4de14", size = 4585420 },
|
||||
{ url = "https://files.pythonhosted.org/packages/43/ab/8f81312d255d713b99ca37479a4cb4b0f48195e530cdc1611990eb8fd04b/pillow-11.2.1-cp313-cp313-musllinux_1_2_x86_64.whl", hash = "sha256:fe15238d3798788d00716637b3d4e7bb6bde18b26e5d08335a96e88564a36b6b", size = 4667655 },
|
||||
{ url = "https://files.pythonhosted.org/packages/94/86/8f2e9d2dc3d308dfd137a07fe1cc478df0a23d42a6c4093b087e738e4827/pillow-11.2.1-cp313-cp313-win32.whl", hash = "sha256:3fe735ced9a607fee4f481423a9c36701a39719252a9bb251679635f99d0f7d2", size = 2332329 },
|
||||
{ url = "https://files.pythonhosted.org/packages/6d/ec/1179083b8d6067a613e4d595359b5fdea65d0a3b7ad623fee906e1b3c4d2/pillow-11.2.1-cp313-cp313-win_amd64.whl", hash = "sha256:74ee3d7ecb3f3c05459ba95eed5efa28d6092d751ce9bf20e3e253a4e497e691", size = 2676388 },
|
||||
{ url = "https://files.pythonhosted.org/packages/23/f1/2fc1e1e294de897df39fa8622d829b8828ddad938b0eaea256d65b84dd72/pillow-11.2.1-cp313-cp313-win_arm64.whl", hash = "sha256:5119225c622403afb4b44bad4c1ca6c1f98eed79db8d3bc6e4e160fc6339d66c", size = 2414950 },
|
||||
{ url = "https://files.pythonhosted.org/packages/c4/3e/c328c48b3f0ead7bab765a84b4977acb29f101d10e4ef57a5e3400447c03/pillow-11.2.1-cp313-cp313t-macosx_10_13_x86_64.whl", hash = "sha256:8ce2e8411c7aaef53e6bb29fe98f28cd4fbd9a1d9be2eeea434331aac0536b22", size = 3192759 },
|
||||
{ url = "https://files.pythonhosted.org/packages/18/0e/1c68532d833fc8b9f404d3a642991441d9058eccd5606eab31617f29b6d4/pillow-11.2.1-cp313-cp313t-macosx_11_0_arm64.whl", hash = "sha256:9ee66787e095127116d91dea2143db65c7bb1e232f617aa5957c0d9d2a3f23a7", size = 3033284 },
|
||||
{ url = "https://files.pythonhosted.org/packages/b7/cb/6faf3fb1e7705fd2db74e070f3bf6f88693601b0ed8e81049a8266de4754/pillow-11.2.1-cp313-cp313t-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:9622e3b6c1d8b551b6e6f21873bdcc55762b4b2126633014cea1803368a9aa16", size = 4445826 },
|
||||
{ url = "https://files.pythonhosted.org/packages/07/94/8be03d50b70ca47fb434a358919d6a8d6580f282bbb7af7e4aa40103461d/pillow-11.2.1-cp313-cp313t-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:63b5dff3a68f371ea06025a1a6966c9a1e1ee452fc8020c2cd0ea41b83e9037b", size = 4527329 },
|
||||
{ url = "https://files.pythonhosted.org/packages/fd/a4/bfe78777076dc405e3bd2080bc32da5ab3945b5a25dc5d8acaa9de64a162/pillow-11.2.1-cp313-cp313t-manylinux_2_28_aarch64.whl", hash = "sha256:31df6e2d3d8fc99f993fd253e97fae451a8db2e7207acf97859732273e108406", size = 4549049 },
|
||||
{ url = "https://files.pythonhosted.org/packages/65/4d/eaf9068dc687c24979e977ce5677e253624bd8b616b286f543f0c1b91662/pillow-11.2.1-cp313-cp313t-manylinux_2_28_x86_64.whl", hash = "sha256:062b7a42d672c45a70fa1f8b43d1d38ff76b63421cbbe7f88146b39e8a558d91", size = 4635408 },
|
||||
{ url = "https://files.pythonhosted.org/packages/1d/26/0fd443365d9c63bc79feb219f97d935cd4b93af28353cba78d8e77b61719/pillow-11.2.1-cp313-cp313t-musllinux_1_2_aarch64.whl", hash = "sha256:4eb92eca2711ef8be42fd3f67533765d9fd043b8c80db204f16c8ea62ee1a751", size = 4614863 },
|
||||
{ url = "https://files.pythonhosted.org/packages/49/65/dca4d2506be482c2c6641cacdba5c602bc76d8ceb618fd37de855653a419/pillow-11.2.1-cp313-cp313t-musllinux_1_2_x86_64.whl", hash = "sha256:f91ebf30830a48c825590aede79376cb40f110b387c17ee9bd59932c961044f9", size = 4692938 },
|
||||
{ url = "https://files.pythonhosted.org/packages/b3/92/1ca0c3f09233bd7decf8f7105a1c4e3162fb9142128c74adad0fb361b7eb/pillow-11.2.1-cp313-cp313t-win32.whl", hash = "sha256:e0b55f27f584ed623221cfe995c912c61606be8513bfa0e07d2c674b4516d9dd", size = 2335774 },
|
||||
{ url = "https://files.pythonhosted.org/packages/a5/ac/77525347cb43b83ae905ffe257bbe2cc6fd23acb9796639a1f56aa59d191/pillow-11.2.1-cp313-cp313t-win_amd64.whl", hash = "sha256:36d6b82164c39ce5482f649b437382c0fb2395eabc1e2b1702a6deb8ad647d6e", size = 2681895 },
|
||||
{ url = "https://files.pythonhosted.org/packages/67/32/32dc030cfa91ca0fc52baebbba2e009bb001122a1daa8b6a79ad830b38d3/pillow-11.2.1-cp313-cp313t-win_arm64.whl", hash = "sha256:225c832a13326e34f212d2072982bb1adb210e0cc0b153e688743018c94a2681", size = 2417234 },
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "sqlparse"
|
||||
version = "0.5.3"
|
||||
source = { registry = "https://pypi.org/simple" }
|
||||
sdist = { url = "https://files.pythonhosted.org/packages/e5/40/edede8dd6977b0d3da179a342c198ed100dd2aba4be081861ee5911e4da4/sqlparse-0.5.3.tar.gz", hash = "sha256:09f67787f56a0b16ecdbde1bfc7f5d9c3371ca683cfeaa8e6ff60b4807ec9272", size = 84999 }
|
||||
wheels = [
|
||||
{ url = "https://files.pythonhosted.org/packages/a9/5c/bfd6bd0bf979426d405cc6e71eceb8701b148b16c21d2dc3c261efc61c7b/sqlparse-0.5.3-py3-none-any.whl", hash = "sha256:cf2196ed3418f3ba5de6af7e82c694a9fbdbfecccdfc72e281548517081f16ca", size = 44415 },
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "tzdata"
|
||||
version = "2025.2"
|
||||
source = { registry = "https://pypi.org/simple" }
|
||||
sdist = { url = "https://files.pythonhosted.org/packages/95/32/1a225d6164441be760d75c2c42e2780dc0873fe382da3e98a2e1e48361e5/tzdata-2025.2.tar.gz", hash = "sha256:b60a638fcc0daffadf82fe0f57e53d06bdec2f36c4df66280ae79bce6bd6f2b9", size = 196380 }
|
||||
wheels = [
|
||||
{ url = "https://files.pythonhosted.org/packages/5c/23/c7abc0ca0a1526a0774eca151daeb8de62ec457e77262b66b359c3c7679e/tzdata-2025.2-py2.py3-none-any.whl", hash = "sha256:1a403fada01ff9221ca8044d701868fa132215d84beb92242d9acd2147f667a8", size = 347839 },
|
||||
]
|
||||
Reference in new issue
Block a user