django-easycart-ng
A simple and flexible shopping cart for Django projects .
django-easycart-ng is a lightweight, reusable shopping cart app for Django. It provides essential cart functionality with a clean API, making it easy to integrate into any Django project.
✨ Features
- Simple Cart Management: Add, remove, and update items with ease.
- Generic Product Support: Works with any product model using a generic
product_idfield. - Wishlist: Allow users to save products for later.
- Session Support: (Coming soon) Support for anonymous users via sessions.
- Admin Integration: Full admin interface for managing carts and wishlists.
- Template Tags: Easy access to cart data in templates.
- Lightweight: Minimal dependencies (only Django).
- Extensible: Easy to customize and extend.
📦 Installation
- Install the package:
pip install django-easycart-ng
- Add
cartto yourINSTALLED_APPS:
INSTALLED_APPS = [
# ...
"cart.apps.CartConfig",
# ...
]
- Run migrations:
python manage.py migrate
- Add the context processor (optional but recommended):
TEMPLATES = [
{
# ...
"OPTIONS": {
"context_processors": [
# ...
"cart.context_processors.cart_total",
],
},
},
]
🚀 Quick Start
Add an item to the cart:
from cart.models import Cart
# Get or create the user's cart
cart, _ = Cart.objects.get_or_create(user=request.user)
# Add an item
cart.add_item(
product_id=1,
quantity=2,
price=99.99,
size="Large", # Extra data
)
Get cart total:
total_price = cart.get_total_price()
total_items = cart.get_total_items()
Use template tags:
{% load cart_tags %}
<p>Total items: {% get_cart_total_items %}</p>
<p>Total price: ${% get_cart_total_price %}</p>
{% if request.user.is_authenticated %}
<a href="{% url 'cart_detail' %}">View Cart</a>
{% endif %}
📚 API Reference
Cart Model
| Method | Description |
|---|---|
add_item(product_id, quantity=1, price=None, **extra_data) |
Add an item to the cart. |
remove_item(item_id) |
Remove an item from the cart. |
update_quantity(item_id, quantity) |
Update the quantity of an item. |
get_total_price() |
Return total price of all items. |
get_total_items() |
Return total number of items. |
clear() |
Remove all items from the cart. |
Wishlist Model
| Method | Description |
|---|---|
add_product(product_id) |
Add a product to the wishlist. |
remove_product(product_id) |
Remove a product from the wishlist. |
has_product(product_id) |
Check if a product is in the wishlist. |
get_product_count() |
Return the number of products in the wishlist. |
🛠️ Development Setup
To contribute to this package, follow these steps:
- Clone the repository:
git clone https://github.com/reza-khalili-dev/django-easycart-ng.git
cd django-easycart-ng
- Create and activate a virtual environment:
python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate
- Install development dependencies:
pip install -e .[dev]
- Run tests:
pytest
📄 License
This project is licensed under the MIT License. See the LICENSE file for details.
⭐ Show Your Support
If you find this package useful, please give it a ⭐ on GitHub!
📧 Contact
- Author: Reza Khalili
- Email: arsalankhalili688@gmail.com
- Linkedin www.linkedin.com/in/reza-khalili-developer
- GitHub: https://github.com/reza-khalili-dev
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file django_easycart_ng-0.1.3.tar.gz.
File metadata
- Download URL: django_easycart_ng-0.1.3.tar.gz
- Upload date:
- Size: 15.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/6.2.0 CPython/3.14.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7c5430527dc4c66c593f3b59b0c846bd5b820cec125dfad8cf07aa7397a3c1e8
|
|
| MD5 |
0243ec713042a052b020f8cd3ba1d1b7
|
|
| BLAKE2b-256 |
eef6a702f01045e58fc7655732ccab4c8b0599f2c802e7ba2af14da6f7b17f64
|
File details
Details for the file django_easycart_ng-0.1.3-py3-none-any.whl.
File metadata
- Download URL: django_easycart_ng-0.1.3-py3-none-any.whl
- Upload date:
- Size: 17.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/6.2.0 CPython/3.14.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ea7db588a5f076fb7db11910680c113d40884aa249c2e0183eaddcaa9e94e1ab
|
|
| MD5 |
529a349725932f38b3c5263c88116ceb
|
|
| BLAKE2b-256 |
7d1f6bbcca07bde361158785e00e4221d9a80d5868bd513b63d9f470ffc65b04
|