version 2
This commit is contained in:
parent
a6552f1692
commit
d8fd7aae82
Binary file not shown.
Binary file not shown.
@ -5,9 +5,6 @@ Generated by 'django-admin startproject' using Django 5.2.7.
|
||||
|
||||
For more information on this file, see
|
||||
https://docs.djangoproject.com/en/5.2/topics/settings/
|
||||
|
||||
For the full list of settings and their values, see
|
||||
https://docs.djangoproject.com/en/5.2/ref/settings/
|
||||
"""
|
||||
|
||||
from pathlib import Path
|
||||
@ -55,12 +52,15 @@ INSTALLED_APPS = [
|
||||
'django.contrib.sessions',
|
||||
'django.contrib.messages',
|
||||
'django.contrib.staticfiles',
|
||||
'rest_framework',
|
||||
'corsheaders',
|
||||
'core',
|
||||
]
|
||||
|
||||
MIDDLEWARE = [
|
||||
'django.middleware.security.SecurityMiddleware',
|
||||
'django.contrib.sessions.middleware.SessionMiddleware',
|
||||
'corsheaders.middleware.CorsMiddleware',
|
||||
'django.middleware.common.CommonMiddleware',
|
||||
'django.middleware.csrf.CsrfViewMiddleware',
|
||||
'django.contrib.auth.middleware.AuthenticationMiddleware',
|
||||
@ -180,3 +180,20 @@ if EMAIL_USE_SSL:
|
||||
# https://docs.djangoproject.com/en/5.2/ref/settings/#default-auto-field
|
||||
|
||||
DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'
|
||||
|
||||
CORS_ALLOWED_ORIGINS = [
|
||||
"http://localhost:3000",
|
||||
"http://127.0.0.1:3000",
|
||||
]
|
||||
CORS_ALLOW_CREDENTIALS = True
|
||||
CORS_ALLOW_ALL_ORIGINS = True
|
||||
|
||||
REST_FRAMEWORK = {
|
||||
'DEFAULT_PERMISSION_CLASSES': [
|
||||
'rest_framework.permissions.IsAuthenticatedOrReadOnly',
|
||||
],
|
||||
'DEFAULT_AUTHENTICATION_CLASSES': [
|
||||
'rest_framework.authentication.SessionAuthentication',
|
||||
'rest_framework.authentication.BasicAuthentication',
|
||||
],
|
||||
}
|
||||
@ -26,4 +26,4 @@ urlpatterns = [
|
||||
|
||||
if settings.DEBUG:
|
||||
urlpatterns += static("/assets/", document_root=settings.BASE_DIR / "assets")
|
||||
urlpatterns += static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)
|
||||
urlpatterns += static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)
|
||||
BIN
backend/core/__pycache__/models.cpython-311.pyc
Normal file
BIN
backend/core/__pycache__/models.cpython-311.pyc
Normal file
Binary file not shown.
BIN
backend/core/__pycache__/serializers.cpython-311.pyc
Normal file
BIN
backend/core/__pycache__/serializers.cpython-311.pyc
Normal file
Binary file not shown.
BIN
backend/core/__pycache__/urls.cpython-311.pyc
Normal file
BIN
backend/core/__pycache__/urls.cpython-311.pyc
Normal file
Binary file not shown.
BIN
backend/core/__pycache__/views.cpython-311.pyc
Normal file
BIN
backend/core/__pycache__/views.cpython-311.pyc
Normal file
Binary file not shown.
33
backend/core/migrations/0003_category_product_category.py
Normal file
33
backend/core/migrations/0003_category_product_category.py
Normal file
@ -0,0 +1,33 @@
|
||||
# Generated by Django 5.2.7 on 2026-03-13 01:38
|
||||
|
||||
import django.db.models.deletion
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('core', '0002_seller_product_seller'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.CreateModel(
|
||||
name='Category',
|
||||
fields=[
|
||||
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||
('name', models.CharField(max_length=100, unique=True)),
|
||||
('slug', models.SlugField(unique=True)),
|
||||
('description', models.TextField(blank=True)),
|
||||
('created_at', models.DateTimeField(auto_now_add=True)),
|
||||
('parent', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='children', to='core.category')),
|
||||
],
|
||||
options={
|
||||
'verbose_name_plural': 'categories',
|
||||
},
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='product',
|
||||
name='category',
|
||||
field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='products', to='core.category'),
|
||||
),
|
||||
]
|
||||
Binary file not shown.
@ -1,6 +1,19 @@
|
||||
from django.db import models
|
||||
from django.contrib.auth.models import User
|
||||
|
||||
class Category(models.Model):
|
||||
name = models.CharField(max_length=100, unique=True)
|
||||
slug = models.SlugField(unique=True)
|
||||
description = models.TextField(blank=True)
|
||||
parent = models.ForeignKey('self', on_delete=models.CASCADE, null=True, blank=True, related_name='children')
|
||||
created_at = models.DateTimeField(auto_now_add=True)
|
||||
|
||||
class Meta:
|
||||
verbose_name_plural = 'categories'
|
||||
|
||||
def __str__(self):
|
||||
return self.name
|
||||
|
||||
class Seller(models.Model):
|
||||
user = models.OneToOneField(User, on_delete=models.CASCADE)
|
||||
store_name = models.CharField(max_length=200)
|
||||
@ -12,6 +25,7 @@ class Seller(models.Model):
|
||||
return self.store_name
|
||||
|
||||
class Product(models.Model):
|
||||
category = models.ForeignKey(Category, on_delete=models.SET_NULL, null=True, blank=True, related_name='products')
|
||||
seller = models.ForeignKey(Seller, on_delete=models.CASCADE, related_name='products', null=True, blank=True)
|
||||
name = models.CharField(max_length=200)
|
||||
description = models.TextField()
|
||||
@ -20,4 +34,4 @@ class Product(models.Model):
|
||||
created_at = models.DateTimeField(auto_now_add=True)
|
||||
|
||||
def __str__(self):
|
||||
return self.name
|
||||
return self.name
|
||||
17
backend/core/serializers.py
Normal file
17
backend/core/serializers.py
Normal file
@ -0,0 +1,17 @@
|
||||
from rest_framework import serializers
|
||||
from .models import Seller, Product, Category
|
||||
|
||||
class CategorySerializer(serializers.ModelSerializer):
|
||||
class Meta:
|
||||
model = Category
|
||||
fields = '__all__'
|
||||
|
||||
class SellerSerializer(serializers.ModelSerializer):
|
||||
class Meta:
|
||||
model = Seller
|
||||
fields = '__all__'
|
||||
|
||||
class ProductSerializer(serializers.ModelSerializer):
|
||||
class Meta:
|
||||
model = Product
|
||||
fields = '__all__'
|
||||
12
backend/core/urls.py
Normal file
12
backend/core/urls.py
Normal file
@ -0,0 +1,12 @@
|
||||
from django.urls import path, include
|
||||
from rest_framework.routers import DefaultRouter
|
||||
from .views import SellerViewSet, ProductViewSet, CategoryViewSet
|
||||
|
||||
router = DefaultRouter()
|
||||
router.register(r'categories', CategoryViewSet)
|
||||
router.register(r'sellers', SellerViewSet)
|
||||
router.register(r'products', ProductViewSet)
|
||||
|
||||
urlpatterns = [
|
||||
path('', include(router.urls)),
|
||||
]
|
||||
15
backend/core/views.py
Normal file
15
backend/core/views.py
Normal file
@ -0,0 +1,15 @@
|
||||
from rest_framework import viewsets
|
||||
from .models import Seller, Product, Category
|
||||
from .serializers import SellerSerializer, ProductSerializer, CategorySerializer
|
||||
|
||||
class CategoryViewSet(viewsets.ModelViewSet):
|
||||
queryset = Category.objects.all()
|
||||
serializer_class = CategorySerializer
|
||||
|
||||
class SellerViewSet(viewsets.ModelViewSet):
|
||||
queryset = Seller.objects.all()
|
||||
serializer_class = SellerSerializer
|
||||
|
||||
class ProductViewSet(viewsets.ModelViewSet):
|
||||
queryset = Product.objects.all()
|
||||
serializer_class = ProductSerializer
|
||||
6
backend/requirements.txt
Normal file
6
backend/requirements.txt
Normal file
@ -0,0 +1,6 @@
|
||||
Django==5.2.7
|
||||
mysqlclient==2.2.7
|
||||
python-dotenv==1.1.1
|
||||
djangorestframework
|
||||
djangorestframework-simplejwt
|
||||
django-cors-headers
|
||||
Some files were not shown because too many files have changed in this diff Show More
Loading…
x
Reference in New Issue
Block a user