Skip to main content

django-fashion-size

PyPI Python Django Release

Django fields for fashion-size.

SizeTypeField stores which size type a column is (dress, adult-shoe). Reading it returns a SizeType.

SizeUnitField stores which size unit a column is (uk-dress-size). Reading it returns a SizeUnit.

SizeField stores the size token (10, 7.5, DD, MD). Pass size_unit_field pointing at a SizeUnitField on this model or a related one ("size_unit", "attribute.size_unit"). Reading it returns a Size; call .convert() on that value.

The source repository is github.com/ababic/django-fashion-size. It depends on fashion-size (CalVer releases on PyPI).

pip install django-fashion-size

Supported Django versions are 6.0 and 6.1 (see django>=6.0,<7 in pyproject.toml). CI runs the test suite against each of those releases and against Django's main branch.

pip install tox
tox

To run a single environment, for example Django 6.0: tox -e py312-django60.

Frontend sources live under frontend/. Lint and build with cd frontend && npm ci && npm run lint && npm run build (then commit any changes under src/django_fashion_size/static/django_fashion_size/). CI runs Ruff in lint.yml and lint/build checks in frontend.yml.

A release is a vX.Y.Z tag matching the version in pyproject.toml. The release workflow publishes that tag only when the tagged commit is on main or a release-* branch. Building the package compiles the size field's CSS and JavaScript from frontend/ into the static files the widget serves. That compile step runs in the release workflow, and it needs Node.js when you build from this repository. An install from PyPI uses the compiled files and does not need Node.

from django.db import models

from django_fashion_size.model_fields import SizeField, SizeUnitField


class Attribute(models.Model):
    size_unit = SizeUnitField()


class AttributeValue(models.Model):
    attribute = models.ForeignKey(Attribute, on_delete=models.CASCADE)
    size = SizeField(size_unit_field="attribute.size_unit")
value = attribute_value.size
from fashion_size.demographics import Demographic

value.convert_to_locale(
    "eu",
    demographic=Demographic(age_group="adult", gender="female"),
)

FashionProductType is a Django TextChoices enum with the same values as fashion_size.product_types.ProductType. Its labels are marked for translation (gettext_lazy), so makemessages can collect them.

FashionProductTypeField stores a product-type slug (shoes). Reading it returns a fashion_size.product_types.ProductType, or None when the value is blank or not a known product type. full_clean rejects values that are not in FashionProductType.values. Its default form field is FashionProductTypeFormField, a select whose options always come from FashionProductType. Passed choices are ignored so the list cannot go stale against fashion-size.

SizeTypeSlug and SizeUnitSlug are Django TextChoices enums. Their values match fashion-size (dress, uk-dress-size). Their labels are gettext_lazy strings (Dress size, UK Dress size), so makemessages can collect them. SizeTypeField and SizeUnitField selects always use those labels, in the active language. Passed choices are ignored so a stale list cannot replace them. SizeTypeField stores one of the size-type slugs and returns the SizeType. A blank column reads as None. Use it when the attribute is the size type, and each value keeps its own source unit and raw token:

class Attribute(models.Model):
    size_type = SizeTypeField()


class AttributeValue(models.Model):
    attribute = models.ForeignKey(Attribute, on_delete=models.CASCADE)
    size_unit = SizeUnitField()
    size = SizeField(size_unit_field="size_unit")

attribute.size_type is a SizeType (dress). attribute_value.size is a Size in whatever unit was supplied (eu-dress-size / 38). Convert from that pair when a UK token is needed; the stored columns stay the source unit and the raw token.

Importing this package registers Django's get_language as the fashion-size display language and makes Size.display() use it. English lengths render as 32" and 81cm; other languages render as 32 in and 81 cm. fashion-size uses that same formatting for UK, US, and AU waist and chest sizes, and for UK, US, and EU band sizes. EU waist and chest labels, AU bands, and French bands keep their region prefix (EU 46). UK 10 and DD stay the same in every language. Cup size also accepts sports-bra alpha labels (XXS, XS, S, MD, LG, XL, XXL). They convert as the same token in every region, and the autocomplete lists them after the letter chart. Size.display() shows MD and LG as M and L; the stored token stays MD and LG. Shoe sizes accept alpha labels too (XXS, XS, S, M, L, XL, XXL), on adult, kids, and baby shoe units. They convert as the same token in every region, and every region's list includes them after the numeric chart. Brand charts ship with fashion-size; pass brand_name and product_type on Size.convert / Size.convert_to_locale. The model fields do not need this package in INSTALLED_APPS.

SizeField's form control is an autocomplete. You type a size and the list shows chart values that start with that text, including those alpha labels. A short select beside the field chooses the region or unit you are typing (UK, EU, in, cm). A "View conversion chart" link to the right of the field opens the conversion chart. Pass show_chart_link=False on SizeField, SizeFormField, or SizeValueWidget when that link is not wanted. The value saved on the model is the token in size_unit_field (10 when the field stores UK dress sizes, even if you typed EU 38). Add django_fashion_size to INSTALLED_APPS so the widget's CSS and script are found.

Pass selection="select" on SizeField, SizeFormField, SizeValueWidget, build_size_value_config, or the React SizeValueControl to use a dropdown of the same values instead of the autocomplete. That is the easier control when one form asks for a size on many variants. The default is selection="autocomplete". Lengths and age bands stay a text field, because they are not a fixed list.

Pass unavailable with stored tokens, or aliases such as medium, for sizes that this context must not offer. Each matching option stays in the list with an (n/a) suffix and cannot be chosen. Submitting one is rejected. The same tokens are resolved for every size unit embedded in the control, so M marks both an adult shoe M and a letter M when both units are on the form.

Length size types (chest, waist, inside-leg, shorts-inseam, trousers-inseam, collar, sleeve) convert between inches and centimetres inside that type's own bounds. Shorts inseam is 2–22 inches, trousers inseam is 24–42, and sleeve is 28–40. The autocomplete uses those bounds.

Label size types (trouser-length, top-length, shoe-width, proportion, age-months, age-years, letter) have one universal unit and no conversion chart. The autocomplete lists the vocabulary (Regular, One size). Age bands have no fixed list: type 6 months or 2-3 years and the stored token is the canonical band (6, 2-3). Aliases such as R and small are stored as regular and S.

The same control is SizeFormField, so a CharField such as AttributeValue.value can use it without becoming a SizeField. Pass the attribute's SizeUnit and the brand and product type you already have. brand_name is the brand's name. product_type_name is the product type's name (Shoes) or slug (shoes). Age group and gender select the chart.

self.fields["value"] = SizeFormField(
    size_unit=attribute.size_unit,
    brand_name=brand_name,
    product_type_name=product_type_name,
    age_group="adult",
    gender="female",
)

Pass entry_region (uk, eu, us, au, or fr; eur is accepted as eu) to lock the region the user types in. The value saved is still the token in the field's size unit, so an EU entry can store a UK size. Suggestions follow that region, including when the region control cannot be changed. When custom_values are on that region select, it stays editable and lists only the locked region and Custom. Choosing Custom limits suggestions to those custom values. Without custom values, the region is shown and cannot be changed. Length and label units have no region list, so entry_region does not apply to them. A chart size that has no such region (waist has no FR) is rejected when the size unit is fixed on the field.

Leave those values unset to read them from other fields. A SizeField still passes its size_unit_field. brand_name_field defaults to brand, and product_type_name_field defaults to product_type. Point them at other names when the form uses those:

value = SizeFormField(
    size_unit_field="size_unit",
    brand_name_field="brand_name",
    product_type_name_field="product_type_name",
)

Using the field outside a Django form

build_size_value_config returns the same JSON the form widget embeds. Pass the size unit, brand, product type, age group, and gender yourself. It does not include the hidden name__entry, name__format, and name__unit inputs, or the sibling field names a Django post uses.

from django_fashion_size import build_size_value_config

config = build_size_value_config(
    size_unit=unit,
    brand_name=brand_name,
    product_type_name=product_type_name,
    age_group="adult",
    gender="female",
    custom_values=["One Size"],
    entry_region="eu",
    label="Size",
    show_chart_link=True,
)

Pass units when the host can switch size units and needs every chart in one payload. Omit it to embed size_unit only.

The autocomplete is also an ESM bundle, django-fashion-size/size-value-field, with react and react-dom left external. Importing it pulls in size_value_field.css. Django admin pages keep using the self-mounting size_value_field.js (React included, with the document observer). A host that renders the component itself should not load that script.

import { SizeValueControl } from "django-fashion-size/size-value-field";

<SizeValueControl
  config={config}
  value={storedToken}
  disabled={disabled}
  showChartLink={config.showChartLink}
  onChange={(token, entry) => {
    // entry is { text, format, unit }
  }}
/>

value is the stored token. Changing it after the first render updates the cell. onChange receives that token and the entry { text, format, unit }. showChartLink (or show_chart_link / config.showChartLink) hides the conversion chart link. selection="select" (or config.selection) renders a dropdown of the unit's values. unavailable (or config.unavailable) lists stored tokens that stay visible, suffixed with (n/a), and cannot be chosen. SizeValueField is the lower-level control (measurement, bundles, choices) for a host that already has those props.

Size description API

fashion_size.descriptions can read a feed string and join sizes back into one. Two POST endpoints expose that to JavaScript and other non-Python clients. They are not mounted until you include them:

path("", include("django_fashion_size.urls"))

POST /size-description-decode/ and POST /size-description-encode/ each accept a JSON object. The caller must have an active authenticated session, and the request must include the CSRF token. source_region is read once for the whole request (uk, eu, us, au, or fr; eur is accepted as eu). items is a list of at most 500 objects. A bad item is reported in results and does not reject the rest of the batch. A bad source_region, preferred_regions list, age_group, gender, or more than 500 items rejects the request.

preferred_regions is also request-level. On decode, each size gains a regions list with that size converted into each preferred region. On encode, chart sizes are converted to the first preferred region before the string is built, and each used size includes the same regions list. Lengths move between inches and centimetres (EU and FR use centimetres). Label sizes keep their token and change wording. age_group and gender are optional, on the request or on the item. age_group (adult, child, or baby) is passed to decode_size_description, so a kids or baby shoe is read only when that age group is set. Omit it and the reading stays adult. gender (female, male, or unisex) does not change the reading. Chart conversion still needs both. Pass brand_name as well when a brand chart should be used; a product type on its own stays on the default chart, because fashion-size requires a brand name alongside a product type.

{
  "source_region": "uk",
  "preferred_regions": ["eu", "us"],
  "age_group": "adult",
  "gender": "female",
  "items": [
    {"value": "UK 10", "product_type": "dresses"}
  ]
}

Encode items send sizes instead of value:

{
  "source_region": "uk",
  "preferred_regions": ["eu"],
  "age_group": "adult",
  "gender": "female",
  "items": [
    {
      "product_type": "dresses",
      "sizes": [{"raw": "10", "size_unit": "uk-dress-size"}]
    }
  ]
}

The encoded text for that item is EU 38.

Metadata

Release files for django-fashion-size 0.13.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for django-fashion-size 0.13.1
File Size Uploaded Provenance Actions
django_fashion_size-0.13.1.tar.gz 116.7 kB With provenance Details for django_fashion_size-0.13.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for django-fashion-size 0.13.1
File Interpreter ABI Platform Actions
django_fashion_size-0.13.1-py3-none-any.whl Python 3 none any Details for django_fashion_size-0.13.1-py3-none-any.whl

Total release size: 211.1 kB

Release files / django_fashion_size-0.13.1.tar.gz

Download URL django_fashion_size-0.13.1.tar.gz
Size 116.7 kB
Tags Source
SHA-256 checksum
How to use checksums
7c0a074aadfd287ef2624cf185d9ceb37333e3ec043e0a24b1fa0cca91e20206
BLAKE2b-256 checksum
How to use checksums
3b4e055efb374d944dbeb726f1c4f11e5615875f66d3b32b05682317e007f764
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 12, 2026.

Transparency log

Release files / django_fashion_size-0.13.1-py3-none-any.whl

Download URL django_fashion_size-0.13.1-py3-none-any.whl
Size 94.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
8d7d8ccd60bbff33a7ae63af83d6e254e0a69282ab51eff7f653b0ce2cdc3d0a
BLAKE2b-256 checksum
How to use checksums
f7bccd1ee22de5a7861f1b5a84035bb2afc3ae72c47a9b053722960dbd5b294b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 12, 2026.

Transparency log

Security for django-fashion-size 0.13.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.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for django_fashion_size-0.13.1.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 12, 2026.

Transparency log

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.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page