Skip to main content

django-easycart-ng

PyPI Python Version Django Version License: MIT GitHub issues

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_id field.
  • 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

  1. Install the package:
pip install django-easycart-ng
  1. Add cart to your INSTALLED_APPS:
INSTALLED_APPS = [
    # ...
    "cart.apps.CartConfig",
    # ...
]
  1. Run migrations:
python manage.py migrate
  1. 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:

  1. Clone the repository:
git clone https://github.com/reza-khalili-dev/django-easycart-ng.git
cd django-easycart-ng
  1. Create and activate a virtual environment:
python -m venv venv
source venv/bin/activate  # On Windows: venv\Scripts\activate
  1. Install development dependencies:
pip install -e .[dev]
  1. 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

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

django_easycart_ng-0.1.3.tar.gz (15.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

django_easycart_ng-0.1.3-py3-none-any.whl (17.4 kB view details)

Uploaded Python 3

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

Hashes for django_easycart_ng-0.1.3.tar.gz
Algorithm Hash digest
SHA256 7c5430527dc4c66c593f3b59b0c846bd5b820cec125dfad8cf07aa7397a3c1e8
MD5 0243ec713042a052b020f8cd3ba1d1b7
BLAKE2b-256 eef6a702f01045e58fc7655732ccab4c8b0599f2c802e7ba2af14da6f7b17f64

See more details on using hashes here.

File details

Details for the file django_easycart_ng-0.1.3-py3-none-any.whl.

File metadata

File hashes

Hashes for django_easycart_ng-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 ea7db588a5f076fb7db11910680c113d40884aa249c2e0183eaddcaa9e94e1ab
MD5 529a349725932f38b3c5263c88116ceb
BLAKE2b-256 7d1f6bbcca07bde361158785e00e4221d9a80d5868bd513b63d9f470ffc65b04

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

0.1.3 This release

2 files

0.1.2

2 files

0.1.1

2 files

0.1.0

2 files

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page