Skip to main content

A Django app for a 'Pay What You Want' pricing model with balance tracking and QR code payments

Project description

django-pwyw

Pay‑what‑you‑want (PWYW) utilities for Django projects. This app provides models and helpers to let your users choose their own price, maintain balance transactions, and manage recurring subscriptions with flexible billing periods.

Features

  • Price suggestions you can display in your UI (PriceSuggestion)
  • Simple user subscription model with daily/weekly/monthly/quarterly/yearly billing (Subscription)
  • Balance transactions with deposits, debits and adjustments (BalanceTransaction)
  • Sensible defaults and i18n labels via Django’s translation utilities

Quick start

  1. Install
pip install django-pwyw

If you are working from source, install the project in editable mode:

pip install -e .
  1. Add to INSTALLED_APPS in your Django settings:
INSTALLED_APPS = [
    # ...
    "pwyw",
]
  1. Apply migrations
python manage.py makemigrations
python manage.py migrate
  1. Optional settings
  • PWYW_CURRENCY — currency code used in string representations (default: "EUR").

Add to your Django settings if you want to override the default:

PWYW_CURRENCY = "USD"

Usage overview

Price suggestions

from pwyw.models import PriceSuggestion

# Pre-populate a few suggestions to show in your UI
PriceSuggestion.objects.bulk_create([
    PriceSuggestion(label="Minimum", amount="5.00", sort_order=10),
    PriceSuggestion(label="Recommended", amount="12.00", sort_order=20),
    PriceSuggestion(label="Supporter", amount="20.00", sort_order=30),
])

active = PriceSuggestion.objects.filter(is_active=True).order_by("sort_order", "amount")

Subscriptions

from decimal import Decimal
from django.contrib.auth import get_user_model
from pwyw.models import Subscription

User = get_user_model()
user = User.objects.first()

sub = Subscription.objects.create(
    user=user,
    amount=Decimal("10.00"),
    billing_period=Subscription.BillingPeriodChoices.MONTHLY,
)

# Read-only generated field for active status (computed from `expired_at`)
sub.is_active  # True/False

Subscriptions enforce amount != 0 and will expire any previous open subscription for the same user when saving a new one.

Balance transactions

from decimal import Decimal
from pwyw.models import BalanceTransaction

txn = BalanceTransaction.objects.create(
    user=user,
    amount=Decimal("25.00"),
    type=BalanceTransaction.TypeChoices.TYPE_DEPOSIT,
    approved=True,
    note="Initial top-up",
)

current = BalanceTransaction.balance_for(user)

Demo & docs

  • Demo templates live under demo/ and may help you scaffold a simple dashboard.
  • Developer docs are in docs/ (see mkdocs.yml). If you use MkDocs, you can preview docs locally with:
pip install mkdocs
mkdocs serve

Development

Clone the repo and set up a virtual environment. Then:

pip install -e .[dev]

Run tests with pytest:

pytest -q

Run type checks (if you use mypy and django-stubs):

mypy

Project layout

  • src/pwyw/ — Django app code (models, forms, utils, URLs)
  • tests/ — test suite (pytest)
  • docs/ — documentation source (MkDocs)
  • demo/ — demo assets/templates
  • Changelog.md — release notes
  • TODO.md — rough roadmap/ideas

Changelog

See Changelog.md for notable changes between versions.

Compatibility

  • Python 3.12+
  • Django 5.x (and Django ORM features like GeneratedField)

Contributing

Issues and pull requests are welcome. Please include tests for any behavior changes. Use black for formatting the code.

Project details


Download files

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

Source Distribution

django_pwyw-0.1.0.tar.gz (24.0 kB view details)

Uploaded Source

Built Distribution

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

django_pwyw-0.1.0-py3-none-any.whl (24.3 kB view details)

Uploaded Python 3

File details

Details for the file django_pwyw-0.1.0.tar.gz.

File metadata

  • Download URL: django_pwyw-0.1.0.tar.gz
  • Upload date:
  • Size: 24.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.3

File hashes

Hashes for django_pwyw-0.1.0.tar.gz
Algorithm Hash digest
SHA256 e5fc527e3dc317088b6fa7b5ea7ec6870b78a112cb315f26357b6b6b925d520a
MD5 7823fa6975b2b1dd96d8570021a362de
BLAKE2b-256 db4b25d452b2e81de9492819f39f3d04c7adfed5167045fe4f1a806ff023d137

See more details on using hashes here.

File details

Details for the file django_pwyw-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: django_pwyw-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 24.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.3

File hashes

Hashes for django_pwyw-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 17ea5a1360063c2108ccac73e274ae92fae5e695c126172a2671be02f1510de7
MD5 840c710c240ce4b45ce67f6fd93e2066
BLAKE2b-256 fa707a25f39a7e4b88e668c36ab302df2691c0849142109dc9d5758115ab5fcc

See more details on using hashes here.

Supported by

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