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
Metadata
Release files for django-easycart-ng 0.1.3
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| django_easycart_ng-0.1.3.tar.gz | 15.9 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| django_easycart_ng-0.1.3-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 33.2 kB
Release files / django_easycart_ng-0.1.3.tar.gz
| Download URL | django_easycart_ng-0.1.3.tar.gz |
|---|---|
| Size | 15.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
7c5430527dc4c66c593f3b59b0c846bd5b820cec125dfad8cf07aa7397a3c1e8
|
|
BLAKE2b-256 checksum How to use checksums |
eef6a702f01045e58fc7655732ccab4c8b0599f2c802e7ba2af14da6f7b17f64
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.14.2
|
Release files / django_easycart_ng-0.1.3-py3-none-any.whl
| Download URL | django_easycart_ng-0.1.3-py3-none-any.whl |
|---|---|
| Size | 17.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
ea7db588a5f076fb7db11910680c113d40884aa249c2e0183eaddcaa9e94e1ab
|
|
BLAKE2b-256 checksum How to use checksums |
7d1f6bbcca07bde361158785e00e4221d9a80d5868bd513b63d9f470ffc65b04
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.14.2
|