{"id":18831391,"url":"https://github.com/django-cms/djangocms-attributes-field","last_synced_at":"2025-10-19T02:11:10.421Z","repository":{"id":42395136,"uuid":"61215988","full_name":"django-cms/djangocms-attributes-field","owner":"django-cms","description":"An opinionated implementation of JSONField for arbitrary HTML element attributes.","archived":false,"fork":false,"pushed_at":"2024-11-22T08:56:11.000Z","size":207,"stargazers_count":26,"open_issues_count":0,"forks_count":17,"subscribers_count":13,"default_branch":"master","last_synced_at":"2025-03-29T04:09:48.956Z","etag":null,"topics":["addon","cms","django","django-cms","python"],"latest_commit_sha":null,"homepage":"https://www.django-cms.org","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/django-cms.png","metadata":{"files":{"readme":"README.rst","changelog":"CHANGELOG.rst","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2016-06-15T14:48:07.000Z","updated_at":"2024-11-22T08:56:11.000Z","dependencies_parsed_at":"2024-06-18T18:29:37.398Z","dependency_job_id":"b7520a27-eab5-489d-be8c-bcc12cdef839","html_url":"https://github.com/django-cms/djangocms-attributes-field","commit_stats":{"total_commits":67,"total_committers":19,"mean_commits":3.526315789473684,"dds":0.7611940298507462,"last_synced_commit":"7c8bc1521e99114918c52a21a5b898494fdd6f59"},"previous_names":[],"tags_count":19,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/django-cms%2Fdjangocms-attributes-field","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/django-cms%2Fdjangocms-attributes-field/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/django-cms%2Fdjangocms-attributes-field/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/django-cms%2Fdjangocms-attributes-field/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/django-cms","download_url":"https://codeload.github.com/django-cms/djangocms-attributes-field/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247289424,"owners_count":20914464,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["addon","cms","django","django-cms","python"],"created_at":"2024-11-08T01:53:45.182Z","updated_at":"2025-10-19T02:11:10.392Z","avatar_url":"https://github.com/django-cms.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"===========================\ndjango CMS Attributes Field\n===========================\n\n|pypi| |coverage|  |python| |django| |djangocms|\n\n\nThis project is an opinionated implementation of JSONField for arbitrary HTML\nelement attributes.\n\nIt aims to provide a sensible means of storing and managing\narbitrary HTML element attributes for later emitting them into templates.\n\nThere are a wide variety of types of attributes and using the \"normal\" Django\nmethod of adding ModelFields for each on a business model is cumbersome at\nbest and moreover may require related tables to allow cases where any number\nof the same type of attribute should be supported (i.e., data-attributes).\nThis can contribute to performance problems.\n\nTo avoid these pitfalls, this package allows all of these attributes to be\nstored together in a single text field in the database as a JSON blob, but\nprovides a nice widget to provide an intuitive, key/value pair interface\nand provide sensible validation of the keys used.\n\n\n.. note::\n\n    This project is considered 3rd party (no supervision by the `django CMS Association \u003chttps://www.django-cms.org/en/about-us/\u003e`_).\n    Join us on `Discord \u003chttps://www.django-cms.org/discord/\u003e`_ for more information.\n\n\n.. image:: preview.gif\n\n\n*******************************************\nContribute to this project and win rewards\n*******************************************\n\nBecause this is a an open-source project, we welcome everyone to\n`get involved in the project \u003chttps://www.django-cms.org/en/contribute/\u003e`_ and\n`receive a reward \u003chttps://www.django-cms.org/en/bounty-program/\u003e`_ for their contribution.\nBecome part of a fantastic community and help us make django CMS the best CMS in the world.\n\nWe'll be delighted to receive your\nfeedback in the form of issues and pull requests. Before submitting your\npull request, please review our `contribution guidelines\n\u003chttp://docs.django-cms.org/en/latest/contributing/index.html\u003e`_.\n\nWe're grateful to all contributors who have helped create and maintain this package.\nContributors are listed at the `contributors \u003chttps://github.com/django-cms/djangocms-attributes-field/graphs/contributors\u003e`_\nsection.\n\n\nDocumentation\n=============\n\nSee ``REQUIREMENTS`` in the `setup.py \u003chttps://github.com/divio/djangocms-attributes-field/blob/master/setup.py\u003e`_\nfile for additional dependencies:\n\n\nInstallation\n------------\n\nFor a manual install:\n\n* run ``pip install djangocms-attributes-field``\n* add ``djangocms_attributes_field`` to your ``INSTALLED_APPS`` (at least for CSP support)\n* run ``python manage.py migrate djangocms_attributes_field``\n\n\nConfiguration\n-------------\n\nAttributeField\n##############\n\nTo use this field in your Models.model: ::\n\n    # models.py\n    ...\n    from django.db import models\n    from djangocms_attributes_field.fields import AttributesField\n    ...\n    MyCoolModel(models.Model):\n        ...\n        attributes = AttributesField()\n\nThat's it!\n\nThere is an optional parameter that can be used when declaring the field: ::\n\n    ``excluded_keys`` : This is a list of strings that will not be accepted as\n                        valid keys\n\nSince version 4, the following keys are always excluded (see\n``djangocms_attributes_fields.fields.default_excluded_keys``) to avoid\nunwanted execution of javascript: ::\n\n    [\"src\", \"href\", \"data\", \"action\", \"on*\"]\n\n``'on*'`` represents any key that starts with ``'on'``.\n\nproperty: [field_name]_str\n++++++++++++++++++++++++++\n\n``AttributeField`` will also provide a handy property ``[field_name]_str``\nthat will emit the stored key/value pairs as a string suitable for inclusion\nin your template for the target HTML element in question. You can use it\nlike this: ::\n\n    # models.py\n    ...\n    MyCoolModel(models.Model):\n        ...\n        html_attributes = AttributesField()\n\n\n    # templates/my_cool_project/template.html\n    ...\n    \u003ca href=\"...\" {{ object.html_attributes_str }}\u003eclick me\u003c/a\u003e\n    ...\n\n(Assuming that ``object`` is a context variable containing a\n``MyCoolModel`` instance.)\n\nIn addition to nicely encapsulating the boring task of converting key/value\npairs into a string with proper escaping and marking-safe, this property also\nensures that *existing* key/value pairs with keys that have since been added\nto the field's ``excluded_keys`` are also not included in the output string.\n\n\nAttributeWidget\n###############\n\nThe ``AttributesWidget`` is already used by default by the ``AttributesField``,\nbut there may be cases where you'd like to override its usage.\n\nThe widget supports two additional parameters: ::\n\n    ``key_attrs`` : A dict of HTML attributes to apply to the key input field\n    ``val_attrs`` : A dict of HTML attributes to apply to the value input field\n\nThese can be useful, for example, if it is necessary to alter the appearance\nof the widget's rendered appearance. Again, for example, let's say we needed\nto make the key and value inputs have specific widths. We could do this like\nso in our ``ModelForm``: ::\n\n    # forms.py\n\n    from django import forms\n    from djangocms_attributes_field.widgets import AttributesWidget\n\n    MyCoolForm(forms.ModelForm):\n        class Meta:\n            fields = ['attributes', ...]\n\n        def __init__(self, *args, **kwargs):\n            super().__init__(*args, **kwargs)\n            self.fields['attributes'].widget = AttributesWidget(key_attrs={'style': 'width:250px'},\n                                                                val_attrs={'style': 'width:500px'})\n\n\nRunning Tests\n-------------\n\nYou can run tests by executing::\n\n    virtualenv env\n    source env/bin/activate\n    pip install -r tests/requirements.txt\n    python tests/settings.py\n\n\n.. |pypi| image:: https://badge.fury.io/py/djangocms-attributes-field.svg\n    :target: http://badge.fury.io/py/djangocms-attributes-field\n.. |coverage| image:: https://codecov.io/gh/django-cms/djangocms-attributes-field/branch/master/graph/badge.svg\n    :target: https://codecov.io/gh/django-cms/djangocms-attributes-field\n\n.. |python| image:: https://img.shields.io/pypi/pyversions/djangocms-attributes-field\n    :alt: PyPI - Python Version\n    :target: https://pypi.org/project/djangocms-attributes-field/\n.. |django| image:: https://img.shields.io/pypi/frameworkversions/django/djangocms-attributes-field\n    :alt: PyPI - Django Versions from Framework Classifiers\n    :target: https://www.djangoproject.com/\n.. |djangocms| image:: https://img.shields.io/pypi/frameworkversions/django-cms/djangocms-attributes-field\n    :alt: PyPI - django CMS Versions from Framework Classifiers\n    :target: https://www.django-cms.org/\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdjango-cms%2Fdjangocms-attributes-field","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdjango-cms%2Fdjangocms-attributes-field","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdjango-cms%2Fdjangocms-attributes-field/lists"}