django-better-admin-arrayfield


Namedjango-better-admin-arrayfield JSON
Version 1.4.2 PyPI version JSON
download
home_pagehttps://github.com/gradam/django-better-admin-arrayfield
SummaryBetter ArrayField widget for admin
upload_time2020-12-08 17:39:39
maintainer
docs_urlNone
authorJakub Semik
requires_python
licenseMIT
keywords django-better-admin-arrayfield
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage
            # Django better admin ArrayField

[![image](https://badge.fury.io/py/django-better-admin-arrayfield.svg)](https://badge.fury.io/py/django-better-admin-arrayfield)

[![Actions Status](https://github.com/gradam/django-better-admin-arrayfield/workflows/tests/badge.svg)](https://github.com/gradam/django-better-admin-arrayfield/actions)

[![image](https://codecov.io/gh/gradam/django-better-admin-arrayfield/branch/master/graph/badge.svg)](https://codecov.io/gh/gradam/django-better-admin-arrayfield)

Better ArrayField widget for admin

Supported Python versions: [![Python 3.5](https://img.shields.io/badge/python-3.5-blue.svg)](https://www.python.org/downloads/release/python-350/) [![Python 3.6](https://img.shields.io/badge/python-3.6-blue.svg)](https://www.python.org/downloads/release/python-360/) [![Python 3.7](https://img.shields.io/badge/python-3.7-blue.svg)](https://www.python.org/downloads/release/python-370/) [![Python 3.8](https://img.shields.io/badge/python-3.8-blue.svg)](https://www.python.org/downloads/release/python-380/)





Supported Django versions: 2.0, 2.1, 2.2, 3.0, 3.1

might work with different django/python versions as well but I did not test that.

It changes comma separated widget to list based in admin panel.

Before:
![Alt text](https://raw.githubusercontent.com/gradam/django-better-admin-arrayfield/master/readme_images/before.jpg "Before")

After:
![Alt text](https://raw.githubusercontent.com/gradam/django-better-admin-arrayfield/master/readme_images/after.png "After")

## Quickstart

Install Django better admin ArrayField:

    pip install django-better-admin-arrayfield

Add it to your \`INSTALLED\_APPS\`:

```python
INSTALLED_APPS = (
    ...
    'django_better_admin_arrayfield',
    ...
)
```


## Usage

`django_better_admin_arrayfield.models.fields.ArrayField` is a drop-in replacement for standard Django `ArrayField`.

Import it like below and use it in your model class definition.
```python
from django_better_admin_arrayfield.models.fields import ArrayField
```

Import DynamicArrayMixin like below
```python
from django_better_admin_arrayfield.admin.mixins import DynamicArrayMixin
```

In your admin class add `DynamicArrayMixin`:
    ...
```python
class MyModelAdmin(admin.ModelAdmin, DynamicArrayMixin):
```

That's it.


### Custom subwidget

By default the subwidget (the one used for each item in the array) will be TextInput. If you want something else, you can use your own specifying it in the `formfield_overrides` of your Admin model:
```python
class MyWidget(DynamicArrayWidget):
    def __init__(self, *args, **kwargs):
        kwargs['subwidget_form'] = MyForm
        super().__init__(*args, **kwargs)

class MyModelAdmin(models.ModelAdmin, DynamicArrayMixin):
    ...
    formfield_overrides = {
        DynamicArrayField: {'widget': MyWidget},
    }
```

If you wanted to have Textarea as the subwidget, you can simply use the included drop-in widget replacement:
```python
from django_better_admin_arrayfield.forms.widgets import DynamicArrayTextareaWidget

class MyModelAdmin(models.ModelAdmin, DynamicArrayMixin):
    ...
    formfield_overrides = {
        DynamicArrayField: {'widget': DynamicArrayTextareaWidget},
    }
```

## Running Tests

Does the code actually work?

    source <YOURVIRTUALENV>/bin/activate
    (myenv) $ pip install tox
    (myenv) $ tox

## Pre-commit hooks

Install pre-commit black hook

    source <YOURVIRTUALENV>/bin/activate
    (myenv) $ pip install -r requirements_dev.txt
    (myenv) $ pre-commit install

## Credits

Inspired by: https://stackoverflow.com/a/49370480/4638248

Tools used in rendering this
    package:

  - [Cookiecutter](https://github.com/audreyr/cookiecutter)
  - [cookiecutter-djangopackage](https://github.com/pydanny/cookiecutter-djangopackage)


# History

## 1.4.2 (2020-12-08)

  - Adjust template to better match django style

## 1.4.1 (2020-12-08)

  - Allow submitting empty array field

## 1.4.0 (2020-10-04)

  - allow choosing subwidget for DynamicArrayWidget

## 1.3.0 (2020-07-09)

  - Handle default values in form field

## 1.2.1 (2020-07-09)

  - Fix tests requirements

## 1.2.0 (2020-07-09)

  - handle default values in model fields

## 1.1.0 (2020-04-28)

  - Add spanish translations

## 1.0.7 (2020-04-27)

  - Add possibility to i18n strings

## 1.0.6 (2020-04-15)

  - Remove debugging print statements
  - use default_app_config for easier integration
  - Support dynamically-added inline forms

## 1.0.5 (2019-12-30)

  - Add python 3.8 and Django 3.0 to tests

## 1.0.4 (2019-09-02)

  - Can add item after removing everything from the list

## 1.0.3 (2019-09-02)

  - Can add item after removing everything from the list
  - Do not call static at startup time

## 1.0.2 (2019-04-03)

  - If field is required empty list raises ValidationError on clean.

## 1.0.1 (2019-02-23)

  - Empty list is no longer recognized as changed.


## 1.0.0 (2019-02-21)

  - First release on PyPI.



            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/gradam/django-better-admin-arrayfield",
    "name": "django-better-admin-arrayfield",
    "maintainer": "",
    "docs_url": null,
    "requires_python": "",
    "maintainer_email": "",
    "keywords": "django-better-admin-arrayfield",
    "author": "Jakub Semik",
    "author_email": "kuba.semik@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/35/4f/e8bdf86d5bba2622d585bec983a0b59f373f4ed00eb948a6907ba35e5585/django-better-admin-arrayfield-1.4.2.tar.gz",
    "platform": "",
    "description": "# Django better admin ArrayField\n\n[![image](https://badge.fury.io/py/django-better-admin-arrayfield.svg)](https://badge.fury.io/py/django-better-admin-arrayfield)\n\n[![Actions Status](https://github.com/gradam/django-better-admin-arrayfield/workflows/tests/badge.svg)](https://github.com/gradam/django-better-admin-arrayfield/actions)\n\n[![image](https://codecov.io/gh/gradam/django-better-admin-arrayfield/branch/master/graph/badge.svg)](https://codecov.io/gh/gradam/django-better-admin-arrayfield)\n\nBetter ArrayField widget for admin\n\nSupported Python versions: [![Python 3.5](https://img.shields.io/badge/python-3.5-blue.svg)](https://www.python.org/downloads/release/python-350/) [![Python 3.6](https://img.shields.io/badge/python-3.6-blue.svg)](https://www.python.org/downloads/release/python-360/) [![Python 3.7](https://img.shields.io/badge/python-3.7-blue.svg)](https://www.python.org/downloads/release/python-370/) [![Python 3.8](https://img.shields.io/badge/python-3.8-blue.svg)](https://www.python.org/downloads/release/python-380/)\n\n\n\n\n\nSupported Django versions: 2.0, 2.1, 2.2, 3.0, 3.1\n\nmight work with different django/python versions as well but I did not test that.\n\nIt changes comma separated widget to list based in admin panel.\n\nBefore:\n![Alt text](https://raw.githubusercontent.com/gradam/django-better-admin-arrayfield/master/readme_images/before.jpg \"Before\")\n\nAfter:\n![Alt text](https://raw.githubusercontent.com/gradam/django-better-admin-arrayfield/master/readme_images/after.png \"After\")\n\n## Quickstart\n\nInstall Django better admin ArrayField:\n\n    pip install django-better-admin-arrayfield\n\nAdd it to your \\`INSTALLED\\_APPS\\`:\n\n```python\nINSTALLED_APPS = (\n    ...\n    'django_better_admin_arrayfield',\n    ...\n)\n```\n\n\n## Usage\n\n`django_better_admin_arrayfield.models.fields.ArrayField` is a drop-in replacement for standard Django `ArrayField`.\n\nImport it like below and use it in your model class definition.\n```python\nfrom django_better_admin_arrayfield.models.fields import ArrayField\n```\n\nImport DynamicArrayMixin like below\n```python\nfrom django_better_admin_arrayfield.admin.mixins import DynamicArrayMixin\n```\n\nIn your admin class add `DynamicArrayMixin`:\n    ...\n```python\nclass MyModelAdmin(admin.ModelAdmin, DynamicArrayMixin):\n```\n\nThat's it.\n\n\n### Custom subwidget\n\nBy default the subwidget (the one used for each item in the array) will be TextInput. If you want something else, you can use your own specifying it in the `formfield_overrides` of your Admin model:\n```python\nclass MyWidget(DynamicArrayWidget):\n    def __init__(self, *args, **kwargs):\n        kwargs['subwidget_form'] = MyForm\n        super().__init__(*args, **kwargs)\n\nclass MyModelAdmin(models.ModelAdmin, DynamicArrayMixin):\n    ...\n    formfield_overrides = {\n        DynamicArrayField: {'widget': MyWidget},\n    }\n```\n\nIf you wanted to have Textarea as the subwidget, you can simply use the included drop-in widget replacement:\n```python\nfrom django_better_admin_arrayfield.forms.widgets import DynamicArrayTextareaWidget\n\nclass MyModelAdmin(models.ModelAdmin, DynamicArrayMixin):\n    ...\n    formfield_overrides = {\n        DynamicArrayField: {'widget': DynamicArrayTextareaWidget},\n    }\n```\n\n## Running Tests\n\nDoes the code actually work?\n\n    source <YOURVIRTUALENV>/bin/activate\n    (myenv) $ pip install tox\n    (myenv) $ tox\n\n## Pre-commit hooks\n\nInstall pre-commit black hook\n\n    source <YOURVIRTUALENV>/bin/activate\n    (myenv) $ pip install -r requirements_dev.txt\n    (myenv) $ pre-commit install\n\n## Credits\n\nInspired by: https://stackoverflow.com/a/49370480/4638248\n\nTools used in rendering this\n    package:\n\n  - [Cookiecutter](https://github.com/audreyr/cookiecutter)\n  - [cookiecutter-djangopackage](https://github.com/pydanny/cookiecutter-djangopackage)\n\n\n# History\n\n## 1.4.2 (2020-12-08)\n\n  - Adjust template to better match django style\n\n## 1.4.1 (2020-12-08)\n\n  - Allow submitting empty array field\n\n## 1.4.0 (2020-10-04)\n\n  - allow choosing subwidget for DynamicArrayWidget\n\n## 1.3.0 (2020-07-09)\n\n  - Handle default values in form field\n\n## 1.2.1 (2020-07-09)\n\n  - Fix tests requirements\n\n## 1.2.0 (2020-07-09)\n\n  - handle default values in model fields\n\n## 1.1.0 (2020-04-28)\n\n  - Add spanish translations\n\n## 1.0.7 (2020-04-27)\n\n  - Add possibility to i18n strings\n\n## 1.0.6 (2020-04-15)\n\n  - Remove debugging print statements\n  - use default_app_config for easier integration\n  - Support dynamically-added inline forms\n\n## 1.0.5 (2019-12-30)\n\n  - Add python 3.8 and Django 3.0 to tests\n\n## 1.0.4 (2019-09-02)\n\n  - Can add item after removing everything from the list\n\n## 1.0.3 (2019-09-02)\n\n  - Can add item after removing everything from the list\n  - Do not call static at startup time\n\n## 1.0.2 (2019-04-03)\n\n  - If field is required empty list raises ValidationError on clean.\n\n## 1.0.1 (2019-02-23)\n\n  - Empty list is no longer recognized as changed.\n\n\n## 1.0.0 (2019-02-21)\n\n  - First release on PyPI.\n\n\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Better ArrayField widget for admin",
    "version": "1.4.2",
    "project_urls": {
        "Homepage": "https://github.com/gradam/django-better-admin-arrayfield"
    },
    "split_keywords": [
        "django-better-admin-arrayfield"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "eb758fc6cfc73c456283c89a80bd8319df61aabcd273cfa37697bc31a00e387b",
                "md5": "e1a61825f2f95b991a8b8bcb02655e6d",
                "sha256": "bfeaa0fa8210a7ea95ee996a6caaa59ecd0c923269f573e6d8319c28dcac5c88"
            },
            "downloads": -1,
            "filename": "django_better_admin_arrayfield-1.4.2-py2.py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "e1a61825f2f95b991a8b8bcb02655e6d",
            "packagetype": "bdist_wheel",
            "python_version": "py2.py3",
            "requires_python": null,
            "size": 13931,
            "upload_time": "2020-12-08T17:39:38",
            "upload_time_iso_8601": "2020-12-08T17:39:38.196735Z",
            "url": "https://files.pythonhosted.org/packages/eb/75/8fc6cfc73c456283c89a80bd8319df61aabcd273cfa37697bc31a00e387b/django_better_admin_arrayfield-1.4.2-py2.py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "354fe8bdf86d5bba2622d585bec983a0b59f373f4ed00eb948a6907ba35e5585",
                "md5": "abfd996869796255ba2c143846947fc5",
                "sha256": "b45423e51bbc0aa31ef658248c058ca8b533a541be4dee9fb8bcd059f8a10a58"
            },
            "downloads": -1,
            "filename": "django-better-admin-arrayfield-1.4.2.tar.gz",
            "has_sig": false,
            "md5_digest": "abfd996869796255ba2c143846947fc5",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 13857,
            "upload_time": "2020-12-08T17:39:39",
            "upload_time_iso_8601": "2020-12-08T17:39:39.356535Z",
            "url": "https://files.pythonhosted.org/packages/35/4f/e8bdf86d5bba2622d585bec983a0b59f373f4ed00eb948a6907ba35e5585/django-better-admin-arrayfield-1.4.2.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2020-12-08 17:39:39",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "gradam",
    "github_project": "django-better-admin-arrayfield",
    "travis_ci": false,
    "coveralls": true,
    "github_actions": true,
    "requirements": [],
    "tox": true,
    "lcname": "django-better-admin-arrayfield"
}
        
Elapsed time: 0.53909s