Skip to content

Commit e815f31

Browse files
Merge pull request #3 from amirhossein-moloki/feat/enhance-attribute-model
Feat/enhance attribute model
2 parents 5e3022d + d83ed8a commit e815f31

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

83 files changed

+3348
-1358
lines changed

.env.example

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
# -----------------------------------------------------------------------------
2+
# D J A N G O
3+
# -----------------------------------------------------------------------------
4+
# A secret key for a particular Django installation. This is used to provide cryptographic signing, and should be set to a unique, unpredictable value.
5+
# Generate a new key here: https://djecrety.ir/
6+
SECRET_KEY='django-insecure-your-secret-key'
7+
8+
# Controls whether the application is in debug mode. Set to False in production.
9+
DEBUG=True
10+
11+
# A list of strings representing the host/domain names that this Django site can serve.
12+
# In production, this should be set to your actual domain name(s).
13+
# Example for production: ALLOWED_HOSTS=yourdomain.com,www.yourdomain.com
14+
ALLOWED_HOSTS='*'
15+
16+
17+
# -----------------------------------------------------------------------------
18+
# D A T A B A S E
19+
# -----------------------------------------------------------------------------
20+
# URL for connecting to the PostgreSQL database.
21+
# Format: postgres://<user>:<password>@<host>:<port>/<dbname>
22+
DATABASE_URL='postgres://user:password@database:5432/db'
23+
24+
25+
# -----------------------------------------------------------------------------
26+
# R E D I S
27+
# -----------------------------------------------------------------------------
28+
# URL for connecting to Redis. Used for caching and Celery.
29+
# Format: redis://<host>:<port>/<db_number>
30+
REDIS_URL='redis://cache:6379/1'
31+
32+
33+
# -----------------------------------------------------------------------------
34+
# C E L E R Y
35+
# -----------------------------------------------------------------------------
36+
# URL for the Celery message broker (uses Redis).
37+
CELERY_BROKER_URL='redis://cache:6379/0'
38+
39+
# URL for the Celery result backend (uses Redis).
40+
CELERY_RESULT_BACKEND='redis://cache:6379/0'
41+
42+
43+
# -----------------------------------------------------------------------------
44+
# E M A I L
45+
# -----------------------------------------------------------------------------
46+
# URL for configuring email sending.
47+
# For development, 'consolemail://' prints emails to the console.
48+
# For production, use a real SMTP server. Example: 'smtp://user:pass@smtp.example.com:587'
49+
EMAIL_URL='consolemail://'
50+
51+
52+
# -----------------------------------------------------------------------------
53+
# S I T E
54+
# -----------------------------------------------------------------------------
55+
# The domain of your site. Used for generating absolute URLs.
56+
DOMAIN='localhost:8000'
57+
58+
# The name of your site.
59+
SITE_NAME='Hypex'
60+
61+
62+
# -----------------------------------------------------------------------------
63+
# S O C I A L A U T H ( G O O G L E )
64+
# -----------------------------------------------------------------------------
65+
# Google OAuth2 credentials for social login.
66+
# Obtain these from the Google API Console: https://console.developers.google.com/
67+
GOOGLE_OAUTH2_KEY='your-google-oauth2-key'
68+
GOOGLE_OAUTH2_SECRET='your-google-oauth2-secret'
69+
70+
71+
# -----------------------------------------------------------------------------
72+
# T H I R D - P A R T Y S E R V I C E S
73+
# -----------------------------------------------------------------------------
74+
75+
# --- SMS.ir ---
76+
# Template ID for sending OTP messages via sms.ir.
77+
SMS_IR_OTP_TEMPLATE_ID='your-sms-ir-otp-template-id'
78+
79+
# --- Postex (Shipping) ---
80+
# Details for the sender to be used with the Postex shipping service.
81+
POSTEX_SENDER_NAME='Your Company Name'
82+
POSTEX_SENDER_PHONE='Your Company Phone'
83+
POSTEX_SENDER_ADDRESS='Your Company Address'
84+
POSTEX_SENDER_POSTAL_CODE='Your Company Postal Code'
85+
POSTEX_FROM_CITY_CODE=1 # City code for the origin of shipments.
86+
POSTEX_SERVICE_TYPE='standard' # Default shipping service type.
87+
88+
# --- Zibal (Payment Gateway) ---
89+
# Your merchant ID for the Zibal payment gateway.
90+
ZIBAL_MERCHANT_ID='your-zibal-merchant-id'

.github/workflows/django.yml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,6 @@ jobs:
6565
EMAIL_HOST_USER: ${{ secrets.EMAIL_HOST_USER }}
6666
EMAIL_HOST_PASSWORD: ${{ secrets.EMAIL_HOST_PASSWORD }}
6767
DEFAULT_FROM_EMAIL: "Hypex Store <${{ secrets.EMAIL_HOST_USER }}>"
68-
STRIPE_PUBLISHABLE_KEY: ${{ secrets.STRIPE_PUBLISHABLE_KEY }}
69-
STRIPE_SECRET_KEY: ${{ secrets.STRIPE_SECRET_KEY }}
70-
STRIPE_WEBHOOK_SECRET: ${{ secrets.STRIPE_WEBHOOK_SECRET }}
7168
GOOGLE_OAUTH2_KEY: ${{ secrets.GOOGLE_OAUTH2_KEY }}
7269
GOOGLE_OAUTH2_SECRET: ${{ secrets.GOOGLE_OAUTH2_SECRET }}
7370
RABBITMQ_DEFAULT_USER: ${{ secrets.RABBITMQ_DEFAULT_USER }}

.gitignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,9 @@ __pycache__/
99
*.DS_Store
1010
*.sock
1111
.env
12+
13+
# Log files
14+
*.log
15+
16+
# Database files
17+
*.rdb

CODE_REVIEW_REPORT.md

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
با احترام،
2+
3+
پس از بررسی دقیق و جامع پروژه شما، مایلم نتایج ارزیابی خود را ارائه دهم. در ابتدا باید بگویم که این پروژه یکی از باکیفیت‌ترین پروژه‌های فروشگاهی است که من بررسی کرده‌ام. معماری آن بسیار تمیز، کدها خوانا و استاندارد، و از تکنولوژی‌های مدرن به بهترین شکل ممکن استفاده شده است. این پروژه یک پایه و اساس فوق‌العاده محکم برای ساخت یک فروشگاه آنلاین حرفه‌ای و مقیاس‌پذیر است.
4+
5+
در ادامه، گزارش کامل ارزیابی به تفکیک بخش‌های درخواستی شما ارائه می‌شود.
6+
7+
---
8+
9+
### **1. نتیجه‌گیری جامع و پیشنهادات**
10+
11+
در این بخش، خلاصه‌ای از یافته‌ها در قالب جداول ارائه شده است.
12+
13+
#### **جدول ۱: قابلیت‌های موجود و وضعیت آن‌ها**
14+
15+
| قابلیت | وضعیت | توضیحات |
16+
| :--- | :--- | :--- |
17+
| **مدیریت کاربران (Account)** | کامل | ثبت‌نام با ایمیل/موبایل (OTP)، ورود، خروج، پروفایل، مدیریت آدرس. |
18+
| **احراز هویت و مجوزها** | کامل | مبتنی بر JWT، مدیریت توکن، مجوزهای دسترسی دقیق و سفارشی. |
19+
| **مدیریت محصولات (Shop)** | کامل | CRUD محصولات، دسته‌بندی‌ها، تگ‌گذاری، مدیریت موجودی. |
20+
| **سیستم نقد و بررسی** | کامل | ثبت نظر فقط برای خریداران، امتیازدهی، مدیریت نظرات. |
21+
| **سبد خرید (Cart)** | کامل | افزودن، حذف، به‌روزرسانی آیتم‌ها (مبتنی بر Session). |
22+
| **مدیریت کوپن تخفیف** | کامل | اعمال کوپن بر سبد خرید، اعتبارسنجی و مدیریت استفاده. |
23+
| **فرآیند ثبت سفارش (Orders)** | کامل | ایجاد سفارش از سبد خرید، مدیریت وضعیت، تاریخچه سفارشات. |
24+
| **سیستم پیشنهاددهنده محصول** | ناقص | زیرساخت با Celery و Redis وجود دارد اما منطق اصلی نیاز به تکمیل دارد. |
25+
| **جستجو و فیلتر محصولات** | کامل | فیلتر بر اساس قیمت، دسته‌بندی، تگ و موجودی؛ جستجو بر اساس نام. |
26+
| **پرداخت آنلاین** | کامل | یکپارچه‌سازی با درگاه زیبال، شامل ایجاد پرداخت و تایید سمت سرور. |
27+
| **ارسال و حمل و نقل** | کامل | یکپارچه‌سازی با Postex برای استعلام هزینه داینامیک و ایجاد خودکار بارنامه. |
28+
| **چت آنلاین (Real-time)** | ناقص | زیرساخت با Django Channels وجود دارد اما قابلیت‌ها نیاز به توسعه دارند. |
29+
30+
#### **جدول ۲: قابلیت‌های پیشنهادی برای اضافه شدن**
31+
32+
| قابلیت پیشنهادی | اهمیت | توضیحات |
33+
| :--- | :--- | :--- |
34+
| **لیست علاقه‌مندی‌ها (Wishlist)** | بالا | به کاربران اجازه می‌دهد محصولات مورد علاقه خود را برای خریدهای آینده ذخیره کنند و نرخ بازگشت کاربر را افزایش می‌دهد. |
35+
| **جستجوی پیشرفته (Elasticsearch)** | بالا | برای فروشگاه‌های بزرگ، جستجوی متنی سریع و هوشمند (Full-text search) با Elasticsearch تجربه کاربری را متحول می‌کند. |
36+
| **مدیریت پیشرفته موجودی انبار** | متوسط | قابلیت‌هایی مانند مدیریت چندین انبار، هشدارهای کاهش موجودی و رزرو موجودی هنگام پرداخت. |
37+
| **سیستم بازاریابی و اطلاع‌رسانی** | متوسط | ارسال ایمیل/پیامک برای کمپین‌های تخفیف، اطلاع‌رسانی موجود شدن محصول و... |
38+
| **داشبورد گزارشات برای مدیران** | بالا | گزارشات فروش روزانه/ماهانه، محصولات پرفروش، کاربران فعال و تحلیل‌های کلیدی دیگر. |
39+
40+
#### **جدول ۳: نقاط قوت و ضعف پروژه**
41+
42+
| نقاط قوت (Strengths) | نقاط ضعف (Weaknesses) |
43+
| :--- | :--- |
44+
| ✅ معماری بسیار تمیز، ماژولار و قابل توسعه | ❌ پوشش تست‌ها ناکافی است (فیلترینگ، موارد مرزی و...). |
45+
| ✅ کیفیت کد بالا، خوانا و پیروی از استانداردهای PEP 8 | ❌ پیکربندی امنیتی برای محیط پروداکشن صحیح نیست (`DEBUG=True`). |
46+
| ✅ بهینه‌سازی عملکرد عالی (کشینگ، کوئری‌های بهینه، Celery) | ❌ برخی منطق‌های کسب‌وکار در چند لایه تکرار شده‌اند (مانند بررسی خرید برای نظر). |
47+
| ✅ سیستم احراز هویت و مجوزهای بسیار امن و مدرن | ❌ منطق محاسبه مالیات به صورت ثابت (Hardcoded) است. |
48+
| ✅ مستندات API خودکار و بسیار باکیفیت با `drf-spectacular` | |
49+
| ✅ یکپارچه‌سازی کامل با سرویس‌های پرداخت (Zibal) و حمل و نقل (Postex) | |
50+
51+
---
52+
53+
### **2. امتیازدهی به هر بخش**
54+
55+
| بخش مورد ارزیابی | امتیاز (از ۱ تا ۵) | دلیل امتیاز |
56+
| :--- | :--- | :--- |
57+
| **ساختار پروژه و معماری** | ⭐️ 4.5 | معماری MVVM بسیار تمیز است. با افزودن یک لایه سرویس می‌توانست عالی باشد. |
58+
| **کیفیت کد** | ⭐️ 5 | کدها بسیار خوانا، استاندارد و با رعایت اصول SOLID و DRY نوشته شده‌اند. |
59+
| **عملکرد و کارایی** | ⭐️ 5 | استفاده هوشمندانه از کش، کوئری‌های بهینه و وظایف پس‌زمینه، عملکرد را تضمین می‌کند. |
60+
| **امنیت** | ⭐️ 4 | منطق احراز هویت و مجوزها عالی است، اما تنظیمات پروداکشن نیاز به اصلاح فوری دارد. |
61+
| **تست‌ها و پوشش کد** | ⭐️ 3.5 | تست‌های موجود باکیفیت هستند اما پوشش آن‌ها برای تضمین کامل قابلیت اطمینان، کافی نیست. |
62+
| **مستندسازی و قابلیت توسعه** | ⭐️ 5 | مستندات API خودکار و عالی است و ساختار پروژه توسعه آینده را بسیار آسان می‌کند. |
63+
64+
---
65+
66+
### **3. راهکارهای عملی برای بهبود**
67+
68+
1. **اولویت اول: اصلاحات امنیتی**
69+
* **اقدام فوری:** در فایل تنظیمات پروداکشن (`prod.py`)، مقادیر زیر را تنظیم کنید:
70+
* `DEBUG = False`
71+
* `ALLOWED_HOSTS = ['your_domain.com', 'api.your_domain.com']`
72+
73+
2. **افزایش پوشش تست‌ها**
74+
* تست‌هایی برای **فیلترینگ، جستجو و مرتب‌سازی** در `ProductViewSet` بنویسید.
75+
* تست‌هایی برای **موارد مرزی (Edge Cases)** اضافه کنید (مثلاً ارسال داده نامعتبر به سریالایزرها).
76+
* یک **تست یکپارچه‌سازی (Integration Test)** برای فرآیند کامل "افزودن به سبد -> اعمال کوپن -> ایجاد سفارش" بنویسید.
77+
78+
3. **بهبود معماری و کاهش تکرار کد**
79+
* یک **لایه سرویس (Service Layer)** به پروژه اضافه کنید. این لایه می‌تواند شامل توابعی باشد که منطق کسب‌وکار را در خود کپسوله می‌کنند. برای مثال:
80+
* یک تابع `can_user_review_product(user, product)` ایجاد کنید و منطق بررسی خرید محصول را در آن قرار دهید تا هم از مدل و هم از ویو فراخوانی شود.
81+
* منطق محاسبه هزینه حمل و نقل و مالیات را از `OrderCreateSerializer` به یک سرویس منتقل کنید تا داینامیک و قابل مدیریت باشد.
82+
83+
4. **بهبودهای نهایی**
84+
* **محاسبه مالیات:** منطق محاسبه مالیات را از حالت ثابت به یک سیستم داینامیک (مثلاً بر اساس نوع محصول یا استان) تغییر دهید.
85+
* **تکمیل قابلیت چت:** قابلیت چت آنلاین را با افزودن ویژگی‌هایی مانند تاریخچه گفتگو، وضعیت آنلاین بودن کاربران و... تکمیل کنید.
86+
87+
امیدوارم این ارزیابی جامع برای شما مفید بوده باشد. این پروژه پتانسیل بسیار بالایی دارد و با انجام بهبودهای پیشنهادی، به یک محصول در سطح کلاس جهانی تبدیل خواهد شد.
88+
89+
موفق باشید.

README.md

-12.9 KB

# Django eCommerce API with Redis JWT Celery Smart Search

A scalable, modular, and performant eCommerce REST API built with Django and Django REST Framework. Features include JWT authentication, Stripe integration, Redis caching, Celery tasks, real-time chat with Django Channels, personalized search, tagging, and more.


🧭 Table of Contents


Hypex E-commerce API

Welcome to the Hypex E-commerce API, a scalable and feature-rich backend solution built with Django and Django REST Framework.

Core Features

  • 🔐 User registration, login/logout, and JWT auth
  • 🛍️ Product catalog, categories, tagging, search
  • 🧺 Cart and order management
  • 💳 Stripe payment integration
  • 🧾 Coupon and discount system
  • 📦 Order history and tracking
  • 🔄 Background task scheduling (Celery + Redis)
  • 📡 Real-time chat (Django Channels)
  • 📬 Email notifications
  • 📄 Auto-generated OpenAPI/Swagger docs
  • 🐳 Docker support (optional)

🧰 Tech Stack

  • Backend: Django, Django REST Framework
  • Auth: JWT, Google OAuth2 (social-auth)
  • Database: PostgreSQL (configurable)
  • Caching/Queue: Redis
  • Background Tasks: Celery
  • Payments: Stripe API
  • Docs: drf-spectacular (OpenAPI/Swagger/Redoc)
  • Containerization: Docker & Docker Compose (optional)

📁 Project Structure

apps/
├── accounts/   → User auth, profiles
├── products/   → Products, categories, tags, search
├── orders/     → Order creation, history, cart
├── payments/   → Stripe integration & webhook
├── chat/       → Real-time chat via Channels
├── core/       → Shared utils, settings

  • Clean & Modular Architecture: Organized into logical Django apps for maintainability.
  • Complete E-commerce Functionality: Covers products, carts, orders, payments, coupons, and more.
  • JWT Authentication: Secure, token-based authentication powered by djoser and simple_jwt.
  • Interactive API Documentation: Auto-generated, interactive API docs using drf-spectacular (OpenAPI 3).
  • Asynchronous Task Processing: Uses Celery with a Redis broker for handling background tasks like sending emails.
  • Performance Optimized: Implements caching with Redis and rate limiting (throttling) to ensure a fast and reliable API.
  • Containerized with Docker: Comes with a complete Docker and Docker Compose setup for easy development and deployment.

🚀 Getting Started

This project is fully containerized. All you need is Docker and Docker Compose to get it up and running.

Prerequisites

  • Python 3.10+
  • PostgreSQL
  • Redis
  • React.js (for frontend, optional)
  • pipenv or pip

Installation & Setup

# 1. Clone the repo
git clone https://github.com/YOUR_USERNAME/hypex-ecommerce-api.git
cd hypex-ecommerce-api

# 2. Create virtual env & install deps
pip install -r requirements.txt

# 3. Configure your environment variables
cp .env.example .env  # then edit with your secrets

# 4. Apply migrations
python manage.py migrate

# 5. Create superuser
python manage.py createsuperuser

# 6. Start Redis & Celery (in separate terminals)
redis-server
celery -A ecommerce_api worker -l info

# 7. Start development server
python manage.py runserver

📘 API Documentation


🔐 Environment Variables

Set these in .env:

SECRET_KEY=your_secret
DATABASE_URL=postgres://user:pass@localhost:5432/dbname
REDIS_HOST=localhost
REDIS_PORT=6379
EMAIL_HOST_USER=your@email.com
EMAIL_HOST_PASSWORD=password
DEFAULT_FROM_EMAIL=noreply@yourdomain.com
STRIPE_PUBLISHABLE_KEY=...
STRIPE_SECRET_KEY=...
STRIPE_WEBHOOK_SECRET=...
GOOGLE_OAUTH2_KEY=...
GOOGLE_OAUTH2_SECRET=...
DOMAIN=localhost
SITE_NAME=Hypex

🔀 Endpoints Overview

👤 User Management

Method Endpoint Description
GET /auth/me/ Get current user profile
PUT /auth/me/ Update user profile
PATCH /auth/me/ Partial update
DELETE /auth/me/ Delete user
POST /auth/reset-password/ Request password reset
POST /auth/reset-password-confirm/ Confirm reset token
POST /auth/set-password/ Set new password

🔐 Authentication

Method Endpoint Description
POST /auth/register/ Register a new user
POST /auth/activate/ Activate account
POST /auth/token/create/ Login
POST /auth/token/refresh/ Refresh JWT token
POST /auth/token/verify/ Verify token
POST /auth/token/destroy/ Logout

🛒 Products

Method Endpoint Description
GET /api/v1/products/ List all products
POST /api/v1/products/ Create a new product
GET /api/v1/products/{slug}/ Retrieve product
PUT /api/v1/products/{slug}/ Update product
PATCH /api/v1/products/{slug}/ Partial update
DELETE /api/v1/products/{slug}/ Delete product
GET /api/v1/products/user-products/ User's own listings

🧭 Categories

Method Endpoint
GET /api/v1/categories/
POST /api/v1/categories/
GET /api/v1/categories/{slug}/
PUT /api/v1/categories/{slug}/
PATCH /api/v1/categories/{slug}/
DELETE /api/v1/categories/{slug}/

🧺 Cart

Method Endpoint
GET /api/v1/cart/
POST /api/v1/cart/{product_id}/add/
DELETE /api/v1/cart/{product_id}/remove/

📦 Orders

Method Endpoint
GET /api/v1/orders/
POST /api/v1/orders/
GET /api/v1/orders/{order_id}/
PUT /api/v1/orders/{order_id}/
PATCH /api/v1/orders/{order_id}/
DELETE /api/v1/orders/{order_id}/

🏷️ Coupons

Method Endpoint
GET /api/v1/coupon/
POST /api/v1/coupon/
GET /api/v1/coupon/{id}/
PUT /api/v1/coupon/{id}/
PATCH /api/v1/coupon/{id}/
DELETE /api/v1/coupon/{id}/
POST /api/v1/coupon/apply-coupon/

💳 Payments

Method Endpoint
POST /payment/process/{order_id}/
GET /payment/completed/
GET /payment/canceled/

💬 Chat

Method Endpoint
GET /api/v1/chat/{product_id}/

  1. Clone the Repository

    git clone https://github.com/m-h-s/E-commerce-api.git
    cd E-commerce-api
  2. Create Environment File The project uses an .env file for configuration. A .env.example is provided as a template. Simply copy it to create your own configuration file:

    cp .env.example .env

    You can customize the variables inside .env if needed, but the default values are configured to work with the Docker setup.

  3. Build and Run with Docker Compose This single command will build the Docker images, create the containers, and run all the services:

    docker-compose up -d --build

    This will start the following services:

    • web: The Django application running on Gunicorn.
    • database: A PostgreSQL database for data storage.
    • cache: A Redis instance for caching and Celery.
    • celery_worker: A Celery worker for processing asynchronous tasks.
    • celery_beat: A Celery beat scheduler for periodic tasks.
    • flower: A web-based monitoring tool for Celery.
    • nginx: A reverse proxy for the Django application and serving static files.

Usage

Once the containers are running, you can access the following services:

  • API: The API is available at http://localhost:80/api/v1/.
  • Interactive API Documentation (Swagger UI): http://localhost:80/api/v1/docs/
  • Celery Monitoring (Flower): http://localhost:5555/

🧪 Running Tests

python manage.py test

📜 License

This project is licensed under the MIT License. See the LICENSE file for details.


For more info, see in-line docstrings and source code. Happy coding!

Let me know if you want to add Docker setup, deployment notes (Heroku, Railway, etc.), or include a logo/banner at the top!

📬 Contact

Made by [Yousef M. Y. Al Sabbah] – Reach out via [yalsabbah@students.iugaza.edu.ps] or open an issue on GitHub.


Tip: Use Postman or Insomnia to explore the API endpoints quickly during development.

To run the test suite, execute the following command in your terminal. This will run the tests inside the web container.

docker-compose exec web pytest

account/migrations/0002_address.py

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# Generated by Django 5.2 on 2025-11-24 18:05
2+
3+
import django.db.models.deletion
4+
from django.conf import settings
5+
from django.db import migrations, models
6+
7+
8+
class Migration(migrations.Migration):
9+
10+
dependencies = [
11+
("account", "0001_initial"),
12+
]
13+
14+
operations = [
15+
migrations.CreateModel(
16+
name="Address",
17+
fields=[
18+
(
19+
"id",
20+
models.BigAutoField(
21+
auto_created=True,
22+
primary_key=True,
23+
serialize=False,
24+
verbose_name="ID",
25+
),
26+
),
27+
("province", models.CharField(max_length=100)),
28+
("city", models.CharField(max_length=100)),
29+
("city_code", models.IntegerField(blank=True, null=True)),
30+
("postal_code", models.CharField(max_length=10)),
31+
("full_address", models.TextField()),
32+
("receiver_name", models.CharField(max_length=100)),
33+
("receiver_phone", models.CharField(max_length=15)),
34+
(
35+
"user",
36+
models.ForeignKey(
37+
on_delete=django.db.models.deletion.CASCADE,
38+
related_name="addresses",
39+
to=settings.AUTH_USER_MODEL,
40+
),
41+
),
42+
],
43+
),
44+
]

account/models.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,3 +117,17 @@ class Meta:
117117
verbose_name = _('user')
118118
verbose_name_plural = _('users')
119119
ordering = ['-pk']
120+
121+
122+
class Address(models.Model):
123+
user = models.ForeignKey(UserAccount, related_name='addresses', on_delete=models.CASCADE)
124+
province = models.CharField(max_length=100)
125+
city = models.CharField(max_length=100)
126+
city_code = models.IntegerField(null=True, blank=True)
127+
postal_code = models.CharField(max_length=10)
128+
full_address = models.TextField()
129+
receiver_name = models.CharField(max_length=100)
130+
receiver_phone = models.CharField(max_length=15)
131+
132+
def __str__(self):
133+
return f'{self.full_address}, {self.city}, {self.province}'

account/serializers.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
from django.db import transaction
33
from rest_framework import serializers
44

5-
from .models import Profile
5+
from .models import Profile, Address
66

77
User = get_user_model()
88

@@ -100,3 +100,9 @@ def update(self, instance, validated_data):
100100

101101
class RefreshTokenSerializer(serializers.Serializer):
102102
refresh = serializers.CharField(required=True, help_text="Refresh token to be blacklisted")
103+
104+
105+
class AddressSerializer(serializers.ModelSerializer):
106+
class Meta:
107+
model = Address
108+
fields = ['id', 'province', 'city', 'city_code', 'postal_code', 'full_address', 'receiver_name', 'receiver_phone']

account/tests.py

Lines changed: 0 additions & 3 deletions
This file was deleted.

account/tests/__init__.py

Whitespace-only changes.

0 commit comments

Comments
 (0)