lfs-samples
Product samples for django-lfs (LFS).
A shop manager marks products as samples and assigns them to other products. A customer can then order the sample of a product from its product page.
What it does
- Adds a Samples tab to every product in the LFS management interface.
- Stores in its own tables:
- whether a product is a sample,
- which samples belong to a product,
- for variants: whether the variant has its own samples or uses those of its parent product.
- Provides template tags to show a product's samples in the shop.
A sample is an ordinary LFS product. When a customer orders it, it goes into the cart like any other product, with its own price, stock and delivery settings. To give samples away for free, give the sample products a price of 0.
Requirements
- django-lfs >= 1.0, < 2 (which requires Django >= 5.2, < 6)
- Python >= 3.12
Installation
-
Install the package:
pip install lfs-samples
-
Add it to
INSTALLED_APPS, after the LFS apps:INSTALLED_APPS = [ # ... the LFS apps ... "lfs_samples", ]
-
Include its URLs in your project's
urls.py. This step is required: the app registers the Samples tab as soon as it is installed, and without these URLs every product page in the management interface fails withNoReverseMatchforlfs_manage_product_samples.from django.urls import include, path urlpatterns = [ # ... path("manage/", include("lfs.manage.urls")), path("manage/samples/", include("lfs_samples.urls")), ]
The templates build all links with
{% url %}, so any prefix works.manage/samples/is recommended: all views of the app belong to the management interface (they require thecore.manage_shoppermission), so they share itsmanage/prefix. -
Create the tables:
python manage.py migrate lfs_samples
Usage in the management interface
Open a product in the management interface and select the Samples tab.
- Is sample: marks the product as a sample. Only products marked this way can be assigned to other products. A sample has no samples of its own, so the rest of the tab is hidden for it.
- Active samples (variants only): when checked, the variant uses the samples assigned to it. When unchecked, the variant uses the samples of its parent product.
- Selectable Samples / Selected Samples: the left list shows the products marked as samples that are not yet assigned (searchable by name or SKU, filterable by category); select some and add them to the product. The right list shows the samples assigned to the product; select some and remove them.
Showing samples in the shop
Load the template tags with {% load lfs_samples_tags %}. They read product from the template context:
{% product_samples %}setsproduct_samplesto the list of the product's samples. For a variant without active samples it returns the samples of the parent product.{% is_sample %}setsis_sampleto whether the product is a sample.{% ifproducthassamples %} ... {% else %} ... {% endifproducthassamples %}renders its first part when samples are assigned to the product itself (it does not fall back to the parent product).
LFS's product form accepts a sample directly: submitted with action=add-sample-to-cart and the sample's id as
sample_id, it adds the sample to the cart. Inside the product form, for example:
{% load i18n lfs_samples_tags %}
{% product_samples %}
{% with sample=product_samples.0 %}
{% if sample %}
<input type="hidden" name="sample_id" value="{{ sample.id }}">
<button type="submit" name="action" value="add-sample-to-cart">{% trans "Order a free sample" %}</button>
{% endif %}
{% endwith %}
lfs-theme already shows this button on the product page when lfs_samples is installed.
The app comes with a German translation.
Development
The tests use pytest with pytest-django and an in-memory SQLite database (see pytest.ini and
lfs_samples/tests/settings.py). In an environment with django-lfs, pytest and pytest-django installed:
pip install -e .
python -m pytest
License
BSD 3-Clause License, see LICENSE.txt.
Metadata
Release files for lfs-samples 1.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| lfs_samples-1.1.tar.gz | 18.6 kB | Without provenance | Details for lfs_samples-1.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| lfs_samples-1.1-py3-none-any.whl | Python 3 | none | any | Details for lfs_samples-1.1-py3-none-any.whl |
Total release size: 41.2 kB
Release files / lfs_samples-1.1.tar.gz
| Download URL | lfs_samples-1.1.tar.gz |
|---|---|
| Size | 18.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
e422faf767ee234369c4d9b80408c490a43c892c25290bd5aa1aa559412d0056
|
|
BLAKE2b-256 checksum How to use checksums |
53f1ef3addfcd8f9ca4ec08b5c05265577381dc19dd8cd81f41e37c8f86998cf
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.3
|
Release files / lfs_samples-1.1-py3-none-any.whl
| Download URL | lfs_samples-1.1-py3-none-any.whl |
|---|---|
| Size | 22.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
3b62a731d88378c2a8cd2e1c2ac0b9a030f262ab92823c7b664383b346d27b94
|
|
BLAKE2b-256 checksum How to use checksums |
ffdb300bc3465b8d6cbf44b043b5ea570e458ac45902351937c9fd56b4db3e35
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.3
|
Security for lfs-samples 1.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.