dalf


Namedalf JSON
Version 0.2.6 PyPI version JSON
download
home_pageNone
SummaryDead simple autocompletion for Django admin list_filter with goodies.
upload_time2024-11-07 18:22:57
maintainerNone
docs_urlNone
authorNone
requires_python>=3.11
licenseNone
keywords django django admin list filter
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            ![Version](https://img.shields.io/badge/version-0.2.6-orange.svg?style=for-the-badge&logo=semver)
![Python](https://img.shields.io/badge/python-3.11+-green.svg?style=for-the-badge&logo=python)
![Django](https://img.shields.io/badge/django-5.0.2-green.svg?style=for-the-badge&logo=django)
[![Ruff](https://img.shields.io/endpoint?style=for-the-badge&url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/v2.json)](https://github.com/astral-sh/ruff)
[![PyPI version](https://img.shields.io/pypi/v/dalf.svg?style=for-the-badge&logo=pypi)](https://pypi.org/project/dalf/)
![PyPI - Downloads](https://img.shields.io/pypi/dm/dalf?style=for-the-badge&logo=pypi)
[![Codecov](https://img.shields.io/codecov/c/github/vigo/django-admin-list-filter?token=6JRNSB6WN1&style=for-the-badge&logo=codecov)](https://codecov.io/gh/vigo/django-admin-list-filter)


# Django Admin List Filter

Dead simple autocompletion for Django admin `list_filter`. This was made using
the libraries shipped with Django (`select2`, `jquery`), Django’s built-in
list filters, and Django’s built-in `AutocompleteJsonView`.

This package is an **improved** version of the previously created 
[django-admin-autocomplete-list-filter][1] package. It supports Django **version 5** and 
above. Please note that the *django-admin-autocomplete-list-filter* package is 
now **deprecated**. Since I am no longer part of the organization where it was 
initially developed, I cannot archive it.

No extra package or install required!

Before **Django Admin List Filter**

![Before Django Admin List Filter](screens/before-dalf.gif)

After **Django Admin List Filter**

![After Django Admin List Filter](screens/after-dalf.gif?1)

---

## 2024-07-03

Thanks to my dear friend [Bahattin Çiniç][bahattincinic]’s warning, He realized
that the necessary HTML, CSS, and JavaScript files were missing from the
published package! I quickly fixed this and published a new version. The `0.1.0`
version is a faulty version. I apologize to the users for this confusion.
Thank you. - vigo

---

## Installation

```bash
pip install dalf
```

Add `dalf` to your `INSTALLED_APPS` in your `settings.py`:

```python
INSTALLED_APPS = [
    "django.contrib.admin",
    "django.contrib.auth",
    "django.contrib.contenttypes",
    "django.contrib.sessions",
    "django.contrib.messages",
    "django.contrib.staticfiles",
    "dalf", # <- add
]
```

---

## Usage

Use `DALFModelAdmin`, inherited from `admin.ModelAdmin` to inject media urls only.
You have some filters;

- `DALFRelatedField`: inherited from `admin.RelatedFieldListFilter`.
- `DALFRelatedFieldAjax`: inherited from `admin.RelatedFieldListFilter`
- `DALFRelatedOnlyField`: inherited from `admin.RelatedOnlyFieldListFilter`.
- `DALFChoicesField`: inherited from `admin.ChoicesFieldListFilter`.

Example `models.py`

```python
# models.py
import uuid

from django.conf import settings
from django.db import models


class Category(models.Model):
    id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
    title = models.CharField(max_length=255)

    def __str__(self):
        return self.title


class Tag(models.Model):
    id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
    name = models.CharField(max_length=255)

    def __str__(self):
        return self.name


class Post(models.Model):
    id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
    category = models.ForeignKey(to='Category', on_delete=models.CASCADE, related_name='posts')
    author = models.ForeignKey(to=settings.AUTH_USER_MODEL, on_delete=models.CASCADE, related_name='posts')
    title = models.CharField(max_length=255)
    body = models.TextField()
    tags = models.ManyToManyField(to='Tag', blank=True)

    def __str__(self):
        return self.title
```

Example `admin.py`:

```python
# admin.py
from dalf.admin import DALFModelAdmin, DALFRelatedOnlyField, DALFRelatedFieldAjax
from django.contrib import admin
from YOURAPP.models import Post

@admin.register(Post)
class PostAdmin(DALFModelAdmin):
    list_filter = (
        ('author', DALFRelatedOnlyField),    # if author has a post!
        ('category', DALFRelatedFieldAjax),  # enable ajax completion for category field (FK)
        ('tags', DALFRelatedFieldAjax),      # enable ajax completion for tags field (M2M)
    )
```

That’s all... There is also `DALFChoicesField`, you can test it out:

```python
# admin.py
from django.contrib import admin
from django.contrib.auth.admin import UserAdmin as BaseUserAdmin
from django.contrib.auth.models import User

from dalf.admin import (
    DALFModelAdmin,
    DALFChoicesField,
    DALFRelatedOnlyField,
    DALFRelatedFieldAjax,
)

from YOURAPP.models import Post, Category, Tag

# must be registered, must have search_fields, required for `author` field demo.
# this is demo purpose only, you can register/import your own/custom User model
class UserAdmin(BaseUserAdmin):
    search_fields = ['username']
    ordering = ['username']

admin.site.unregister(User)
admin.site.register(User, UserAdmin)

@admin.register(Post)
class PostAdmin(DALFModelAdmin):
    list_filter = (
        ('author', DALFChoicesField),        # enable autocomplete w/o ajax (FK)
        ('category', DALFRelatedFieldAjax),  # enable ajax completion for category field (FK)
        ('tags', DALFRelatedOnlyField),      # enable ajax completion for tags field (M2M) if posts has any tag!
    )

# must be registered, must have search_fields
@admin.register(Category)
class CategoryAdmin(admin.ModelAdmin):
    search_fields = ['title',]
    ordering = ['title']


# must be registered, must have search_fields
@admin.register(Tag)
class TagAdmin(admin.ModelAdmin):
    search_fields = ['name',]
    ordering = ['name']

```

### Extras

I mostly use `django-timezone-field`, here is an illustration of timezone
completion w/o **ajax**:

```bash
pip install django-timezone-field
```

Now add `timezone` field to `Post` model:

```python
# modify models.py, add new ones
# ...

from timezone_field import TimeZoneField                 # <- add this line

class Post(models.Model):
    # all the other fiels
    timezone = TimeZoneField(default=settings.TIME_ZONE) # <- add this line
    
    # rest of the code
```

Now, just add `timezone` as regular `list_filter`:

```python
# modify admin.py, add new ones

@admin.register(Post)
class PostAdmin(DALFModelAdmin):
    # previous codes
    list_filter = (
        # previous filters
        ('timezone', DALFChoicesField), # <- add this line
    )
```

That’s it!

---

## Contributor(s)

* [Uğur Özyılmazel](https://github.com/vigo) - Creator, maintainer
* [Ehco](https://github.com/Ehco1996) - Contributor
* [Bahattin Çiniç][bahattincinic] - Bug Report!
* [Nguyễn Hồng Quân](https://github.com/hongquan) - Contributor

---

## Contribute

All PR’s are welcome!

1. `fork` (https://github.com/vigo/django-admin-list-filter/fork)
1. Create your `branch` (`git checkout -b my-feature`)
1. `commit` yours (`git commit -am 'add some functionality'`)
1. `push` your `branch` (`git push origin my-feature`)
1. Than create a new **Pull Request**!

I am not very proficient in JavaScript. Therefore, any support, suggestions,
and feedback are welcome to help improve the project. Feel free to open
pull requests!

---

## Development

Clone the repo somewhere, and install with:

```bash
pip install -r requirements-dev.txt
pip install -e /path/to/dalf
pre-commit install
```

And play with the filters :)

## Publish

Note to my self:

```bash
pip install build twine
rake -T

rake build           # Build package
rake bump[revision]  # Bump version: major,minor,patch
rake clean           # Remove/Delete build..
rake test            # Run tests
rake upload:main     # Upload package to main distro (release)
rake upload:test     # Upload package to test distro
```

---

## Change Log

**2024-11-07**

- Fix dark-mode ajax autocompletion colors - [Nguyễn Hồng Quân](https://github.com/hongquan)

**2024-09-06**

- Fix dark-mode text color.

---

**2024-08-25**

- Fix extend media in `DALFModelAdmin` without overriding default assets - [Bahattin][bahattincinic]

---

**2024-08-16**

- Add `gettextSafe` function to handle missing gettext in Django - [Bahattin][bahattincinic]

---

**2024-07-14**

- Fix choice.display last element issue

---

**2024-07-03**

- Now package is working fine :) Thanks to [Bahattin][bahattincinic]!

---

You can read the whole story [here][changelog].

---

## License

This project is licensed under MIT

---

This project is intended to be a safe, welcoming space for collaboration, and
contributors are expected to adhere to the [code of conduct][coc].

[1]: https://github.com/demiroren-teknoloji/django-admin-autocomplete-list-filter "Deprecated, old package"
[coc]: https://github.com/vigo/django-admin-list-filter/blob/main/CODE_OF_CONDUCT.md
[changelog]: https://github.com/vigo/django-admin-list-filter/blob/main/CHANGELOG.md
[bahattincinic]: https://github.com/bahattincinic

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "dalf",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.11",
    "maintainer_email": null,
    "keywords": "django, django admin, list filter",
    "author": null,
    "author_email": "U\u011fur \u00d6zy\u0131lmazel <ugurozyilmazel@gmail.com>",
    "download_url": "https://files.pythonhosted.org/packages/ed/3f/d23888f474268689278844dbff978a5a22cd55399548ac12c600a22fc1ec/dalf-0.2.6.tar.gz",
    "platform": null,
    "description": "![Version](https://img.shields.io/badge/version-0.2.6-orange.svg?style=for-the-badge&logo=semver)\n![Python](https://img.shields.io/badge/python-3.11+-green.svg?style=for-the-badge&logo=python)\n![Django](https://img.shields.io/badge/django-5.0.2-green.svg?style=for-the-badge&logo=django)\n[![Ruff](https://img.shields.io/endpoint?style=for-the-badge&url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/v2.json)](https://github.com/astral-sh/ruff)\n[![PyPI version](https://img.shields.io/pypi/v/dalf.svg?style=for-the-badge&logo=pypi)](https://pypi.org/project/dalf/)\n![PyPI - Downloads](https://img.shields.io/pypi/dm/dalf?style=for-the-badge&logo=pypi)\n[![Codecov](https://img.shields.io/codecov/c/github/vigo/django-admin-list-filter?token=6JRNSB6WN1&style=for-the-badge&logo=codecov)](https://codecov.io/gh/vigo/django-admin-list-filter)\n\n\n# Django Admin List Filter\n\nDead simple autocompletion for Django admin `list_filter`. This was made using\nthe libraries shipped with Django (`select2`, `jquery`), Django\u2019s built-in\nlist filters, and Django\u2019s built-in `AutocompleteJsonView`.\n\nThis package is an **improved** version of the previously created \n[django-admin-autocomplete-list-filter][1] package. It supports Django **version 5** and \nabove. Please note that the *django-admin-autocomplete-list-filter* package is \nnow **deprecated**. Since I am no longer part of the organization where it was \ninitially developed, I cannot archive it.\n\nNo extra package or install required!\n\nBefore **Django Admin List Filter**\n\n![Before Django Admin List Filter](screens/before-dalf.gif)\n\nAfter **Django Admin List Filter**\n\n![After Django Admin List Filter](screens/after-dalf.gif?1)\n\n---\n\n## 2024-07-03\n\nThanks to my dear friend [Bahattin \u00c7ini\u00e7][bahattincinic]\u2019s warning, He realized\nthat the necessary HTML, CSS, and JavaScript files were missing from the\npublished package! I quickly fixed this and published a new version. The `0.1.0`\nversion is a faulty version. I apologize to the users for this confusion.\nThank you. - vigo\n\n---\n\n## Installation\n\n```bash\npip install dalf\n```\n\nAdd `dalf` to your `INSTALLED_APPS` in your `settings.py`:\n\n```python\nINSTALLED_APPS = [\n    \"django.contrib.admin\",\n    \"django.contrib.auth\",\n    \"django.contrib.contenttypes\",\n    \"django.contrib.sessions\",\n    \"django.contrib.messages\",\n    \"django.contrib.staticfiles\",\n    \"dalf\", # <- add\n]\n```\n\n---\n\n## Usage\n\nUse `DALFModelAdmin`, inherited from `admin.ModelAdmin` to inject media urls only.\nYou have some filters;\n\n- `DALFRelatedField`: inherited from `admin.RelatedFieldListFilter`.\n- `DALFRelatedFieldAjax`: inherited from `admin.RelatedFieldListFilter`\n- `DALFRelatedOnlyField`: inherited from `admin.RelatedOnlyFieldListFilter`.\n- `DALFChoicesField`: inherited from `admin.ChoicesFieldListFilter`.\n\nExample `models.py`\n\n```python\n# models.py\nimport uuid\n\nfrom django.conf import settings\nfrom django.db import models\n\n\nclass Category(models.Model):\n    id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)\n    title = models.CharField(max_length=255)\n\n    def __str__(self):\n        return self.title\n\n\nclass Tag(models.Model):\n    id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)\n    name = models.CharField(max_length=255)\n\n    def __str__(self):\n        return self.name\n\n\nclass Post(models.Model):\n    id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)\n    category = models.ForeignKey(to='Category', on_delete=models.CASCADE, related_name='posts')\n    author = models.ForeignKey(to=settings.AUTH_USER_MODEL, on_delete=models.CASCADE, related_name='posts')\n    title = models.CharField(max_length=255)\n    body = models.TextField()\n    tags = models.ManyToManyField(to='Tag', blank=True)\n\n    def __str__(self):\n        return self.title\n```\n\nExample `admin.py`:\n\n```python\n# admin.py\nfrom dalf.admin import DALFModelAdmin, DALFRelatedOnlyField, DALFRelatedFieldAjax\nfrom django.contrib import admin\nfrom YOURAPP.models import Post\n\n@admin.register(Post)\nclass PostAdmin(DALFModelAdmin):\n    list_filter = (\n        ('author', DALFRelatedOnlyField),    # if author has a post!\n        ('category', DALFRelatedFieldAjax),  # enable ajax completion for category field (FK)\n        ('tags', DALFRelatedFieldAjax),      # enable ajax completion for tags field (M2M)\n    )\n```\n\nThat\u2019s all... There is also `DALFChoicesField`, you can test it out:\n\n```python\n# admin.py\nfrom django.contrib import admin\nfrom django.contrib.auth.admin import UserAdmin as BaseUserAdmin\nfrom django.contrib.auth.models import User\n\nfrom dalf.admin import (\n    DALFModelAdmin,\n    DALFChoicesField,\n    DALFRelatedOnlyField,\n    DALFRelatedFieldAjax,\n)\n\nfrom YOURAPP.models import Post, Category, Tag\n\n# must be registered, must have search_fields, required for `author` field demo.\n# this is demo purpose only, you can register/import your own/custom User model\nclass UserAdmin(BaseUserAdmin):\n    search_fields = ['username']\n    ordering = ['username']\n\nadmin.site.unregister(User)\nadmin.site.register(User, UserAdmin)\n\n@admin.register(Post)\nclass PostAdmin(DALFModelAdmin):\n    list_filter = (\n        ('author', DALFChoicesField),        # enable autocomplete w/o ajax (FK)\n        ('category', DALFRelatedFieldAjax),  # enable ajax completion for category field (FK)\n        ('tags', DALFRelatedOnlyField),      # enable ajax completion for tags field (M2M) if posts has any tag!\n    )\n\n# must be registered, must have search_fields\n@admin.register(Category)\nclass CategoryAdmin(admin.ModelAdmin):\n    search_fields = ['title',]\n    ordering = ['title']\n\n\n# must be registered, must have search_fields\n@admin.register(Tag)\nclass TagAdmin(admin.ModelAdmin):\n    search_fields = ['name',]\n    ordering = ['name']\n\n```\n\n### Extras\n\nI mostly use `django-timezone-field`, here is an illustration of timezone\ncompletion w/o **ajax**:\n\n```bash\npip install django-timezone-field\n```\n\nNow add `timezone` field to `Post` model:\n\n```python\n# modify models.py, add new ones\n# ...\n\nfrom timezone_field import TimeZoneField                 # <- add this line\n\nclass Post(models.Model):\n    # all the other fiels\n    timezone = TimeZoneField(default=settings.TIME_ZONE) # <- add this line\n    \n    # rest of the code\n```\n\nNow, just add `timezone` as regular `list_filter`:\n\n```python\n# modify admin.py, add new ones\n\n@admin.register(Post)\nclass PostAdmin(DALFModelAdmin):\n    # previous codes\n    list_filter = (\n        # previous filters\n        ('timezone', DALFChoicesField), # <- add this line\n    )\n```\n\nThat\u2019s it!\n\n---\n\n## Contributor(s)\n\n* [U\u011fur \u00d6zy\u0131lmazel](https://github.com/vigo) - Creator, maintainer\n* [Ehco](https://github.com/Ehco1996) - Contributor\n* [Bahattin \u00c7ini\u00e7][bahattincinic] - Bug Report!\n* [Nguy\u1ec5n H\u1ed3ng Qu\u00e2n](https://github.com/hongquan) - Contributor\n\n---\n\n## Contribute\n\nAll PR\u2019s are welcome!\n\n1. `fork` (https://github.com/vigo/django-admin-list-filter/fork)\n1. Create your `branch` (`git checkout -b my-feature`)\n1. `commit` yours (`git commit -am 'add some functionality'`)\n1. `push` your `branch` (`git push origin my-feature`)\n1. Than create a new **Pull Request**!\n\nI am not very proficient in JavaScript. Therefore, any support, suggestions,\nand feedback are welcome to help improve the project. Feel free to open\npull requests!\n\n---\n\n## Development\n\nClone the repo somewhere, and install with:\n\n```bash\npip install -r requirements-dev.txt\npip install -e /path/to/dalf\npre-commit install\n```\n\nAnd play with the filters :)\n\n## Publish\n\nNote to my self:\n\n```bash\npip install build twine\nrake -T\n\nrake build           # Build package\nrake bump[revision]  # Bump version: major,minor,patch\nrake clean           # Remove/Delete build..\nrake test            # Run tests\nrake upload:main     # Upload package to main distro (release)\nrake upload:test     # Upload package to test distro\n```\n\n---\n\n## Change Log\n\n**2024-11-07**\n\n- Fix dark-mode ajax autocompletion colors - [Nguy\u1ec5n H\u1ed3ng Qu\u00e2n](https://github.com/hongquan)\n\n**2024-09-06**\n\n- Fix dark-mode text color.\n\n---\n\n**2024-08-25**\n\n- Fix extend media in `DALFModelAdmin` without overriding default assets - [Bahattin][bahattincinic]\n\n---\n\n**2024-08-16**\n\n- Add `gettextSafe` function to handle missing gettext in Django - [Bahattin][bahattincinic]\n\n---\n\n**2024-07-14**\n\n- Fix choice.display last element issue\n\n---\n\n**2024-07-03**\n\n- Now package is working fine :) Thanks to [Bahattin][bahattincinic]!\n\n---\n\nYou can read the whole story [here][changelog].\n\n---\n\n## License\n\nThis project is licensed under MIT\n\n---\n\nThis project is intended to be a safe, welcoming space for collaboration, and\ncontributors are expected to adhere to the [code of conduct][coc].\n\n[1]: https://github.com/demiroren-teknoloji/django-admin-autocomplete-list-filter \"Deprecated, old package\"\n[coc]: https://github.com/vigo/django-admin-list-filter/blob/main/CODE_OF_CONDUCT.md\n[changelog]: https://github.com/vigo/django-admin-list-filter/blob/main/CHANGELOG.md\n[bahattincinic]: https://github.com/bahattincinic\n",
    "bugtrack_url": null,
    "license": null,
    "summary": "Dead simple autocompletion for Django admin list_filter with goodies.",
    "version": "0.2.6",
    "project_urls": {
        "Homepage": "https://github.com/vigo/django-admin-list-filter",
        "Issues": "https://github.com/vigo/django-admin-list-filter/issues"
    },
    "split_keywords": [
        "django",
        " django admin",
        " list filter"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "8e1020fc728baaa1e549cc554d5179735a4d6b68de1600509a01b3c2adf13f3a",
                "md5": "ad871403be93967e57d90b18f257c62a",
                "sha256": "c0b8a87b092645de4b5dd03238919656798fc2d1801cd615483214f259dcf437"
            },
            "downloads": -1,
            "filename": "dalf-0.2.6-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "ad871403be93967e57d90b18f257c62a",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.11",
            "size": 9921,
            "upload_time": "2024-11-07T18:22:55",
            "upload_time_iso_8601": "2024-11-07T18:22:55.416337Z",
            "url": "https://files.pythonhosted.org/packages/8e/10/20fc728baaa1e549cc554d5179735a4d6b68de1600509a01b3c2adf13f3a/dalf-0.2.6-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "ed3fd23888f474268689278844dbff978a5a22cd55399548ac12c600a22fc1ec",
                "md5": "ef454cc46b901485d68ccb0282439e77",
                "sha256": "12ecb15f119e18d63b95e35ce742d8338b4bff555e92cd049471bb6604d63ce9"
            },
            "downloads": -1,
            "filename": "dalf-0.2.6.tar.gz",
            "has_sig": false,
            "md5_digest": "ef454cc46b901485d68ccb0282439e77",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.11",
            "size": 12344,
            "upload_time": "2024-11-07T18:22:57",
            "upload_time_iso_8601": "2024-11-07T18:22:57.315780Z",
            "url": "https://files.pythonhosted.org/packages/ed/3f/d23888f474268689278844dbff978a5a22cd55399548ac12c600a22fc1ec/dalf-0.2.6.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-11-07 18:22:57",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "vigo",
    "github_project": "django-admin-list-filter",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "dalf"
}
        
Elapsed time: 2.14127s