Skip to main content

django-easycart-ng

PyPI version 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.2.tar.gz (15.7 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.2-py3-none-any.whl (17.2 kB view details)

Uploaded Python 3

File details

Details for the file django_easycart_ng-0.1.2.tar.gz.

File metadata

  • Download URL: django_easycart_ng-0.1.2.tar.gz
  • Upload date:
  • Size: 15.7 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.2.tar.gz
Algorithm Hash digest
SHA256 571f7d91b1c49294b5ce92a82b094c646359cf7c125b65f667f8269346131a03
MD5 198c42fab2839ccf89417c3778bb38e6
BLAKE2b-256 866b9cbbaca658a45324d42b8ab4c0b2b75311e8ee2f22fdbf07d65966c00520

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for django_easycart_ng-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 f7650d778eb04141d669d50a958e42762816edfcacfabcc57706278157390e22
MD5 fdb70e1a382d38499da6ce14b0c05a70
BLAKE2b-256 b7d4db194b7940dcdf45f550a15b5109d7336e0eb7dde1b4240bdd41a036313d

See more details on using hashes here.

Release history Release notifications | RSS feed

0.1.3

2 files

This release

0.1.2 This release

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