--- id: djangocms-attributes-field version: "4.1.2" license: BSD-3-Clause license_treatment: permissive maintenance: active --- # djangocms-attributes-field — Adds attributes to Django models. License: permissive · Maintenance: active · Downloads: 82.3K/mo ## What it is and what it does This package provides an opinionated JSONField implementation for Django models that need to store arbitrary HTML element attributes without creating separate database columns or related tables for each attribute type. It solves the problem of managing flexible, schema-less attributes like data-* attributes or custom HTML properties that would otherwise require either many individual model fields or complex relational structures. The package includes an AttributesField that stores key-value pairs as JSON and an AttributesWidget that provides an intuitive admin interface for editing these pairs. It automatically excludes dangerous keys like 'src', 'href', 'data', 'action', and any key starting with 'on' to prevent unintended JavaScript execution. The field also provides a convenience property that renders stored attributes as an HTML-safe string ready for template inclusion. Use it for: - Store custom data-* attributes on Django model instances without creating separate fields for each attribute type. - Manage flexible HTML element attributes in a Django CMS plugin or page extension without schema migration overhead. - Build admin forms where content editors can add arbitrary key-value pairs to HTML elements with a user-friendly widget interface. - Avoid performance problems from excessive database columns or join tables when a model needs to support many optional attributes. - Render HTML elements with dynamic attributes in templates by using the field's _str property for safe, escaped output. ## Worth the install? AI-flagged interpretation of the facts above — verify before relying. Provides a Django model field and widget for storing and managing arbitrary HTML element attributes as JSON, with validation and template-safe string rendering. Yes. This package is actively maintained, has no known vulnerabilities, carries a permissive license, and solves a real problem for Django projects that need flexible HTML attributes. The low install friction and single dependency on django-cms make it a straightforward addition to Django CMS sites. Use it when you need to store arbitrary attributes without schema bloat. ## Install pip install djangocms-attributes-field uv add djangocms-attributes-field poetry add djangocms-attributes-field ## Installing djangocms-attributes-field Before you install: Low install friction with a single runtime dependency on django-cms. The package is actively maintained with a recent release and no known vulnerabilities. License in practice: BSD-3-Clause is a permissive license; you can use, modify, and distribute this package with minimal restrictions, provided you include the license notice. Quickstart: pip install djangocms-attributes-field # In models.py from djangocms_attributes_field.fields import AttributesField class MyCoolModel(models.Model): attributes = AttributesField() # In template
click me
Requires django-cms as a runtime dependency and Python 3.9 or later. Verify before relying: - Performance characteristics when storing large numbers of attributes or very large attribute values in a single field. - Specific Django and Django CMS version compatibility beyond the classifiers listed (4.2, 5.0, 5.1, 5.2 for Django; 3.11, 4.1, 5.0 for Django CMS). ## Package facts - License: BSD-3-Clause (permissive) - Python support: supports_current - Install friction: low - Maintenance: active - Downloads: 82.3K/month (top 15,000 on PyPI) - Known vulnerabilities: none known ## Tags django html attributes field, json field html attributes, django model attributes storage, key-value html attributes django, django cms attributes widget, html element attributes django, json attributes field django, django-cms, html-attributes, json-field [View on SkillFed](https://skillfed.io/packages/djangocms-attributes-field) · [View on PyPI](https://pypi.org/project/djangocms-attributes-field/)