{ "info": { "author": "Alexander Frenzel", "author_email": "alex@relatedworks.com", "bugtrack_url": null, "classifiers": [ "Development Status :: 4 - Beta", "Environment :: Web Environment", "Framework :: Django", "Intended Audience :: Developers", "License :: OSI Approved :: BSD License", "Operating System :: OS Independent", "Programming Language :: Python", "Programming Language :: Python :: 3", "Programming Language :: Python :: 3.6", "Programming Language :: Python :: 3.7", "Topic :: Software Development :: Libraries :: Python Modules" ], "description": "# django-admin-display\n\n![Version](https://img.shields.io/pypi/v/django-admin-display.svg)\n![Build status](https://travis-ci.org/escaped/django-admin-display.png?branch=master)\n![Coverage](https://coveralls.io/repos/escaped/django-admin-display/badge.png?branch=master)\n![Python Versions](https://img.shields.io/pypi/pyversions/django-admin-display.svg)\n![License](https://img.shields.io/pypi/l/django-admin-display.svg)\n\nSimplifies the use of function attributes (eg. `short_description`) for the django admin and makes mypy happy :)\n\n\n## Requirements\n\n- Python >= 3.6\n- Django >= 1.11\n\n\n## Usage\n\nIf you want to change the behaviour of how Django displays a read-only value in the admin interface,\nyou can add some [special attributes](>https://docs.djangoproject.com/en/2.1/ref/contrib/admin/#django.contrib.admin.ModelAdmin.list_display) to the corresponding method.\nSupported values are\n\n`short_description` \n Customize the column\u2019s title of the callable.\n \n`empty_value_display` \n Show this value instead, if the value of a field is `None`, an empty string, or an iterable without elements.\n \n`admin_order_field` \n Indicate that the value is represented by a certain database field.\n \n`boolean` \n Display a pretty \u201con\u201d or \u201coff\u201d icon if the method returns a boolean.\n \n`allow_tags` (deprecated since Django 1.9) \n Disable auto-escaping.\n\nThe following example shows, how you normally apply these attributes to an `AdminModel` or a `Model` method.\n\n class Company(models.Model):\n ...\n\n def owner(self) -> bool:\n return self.owner.last_name\n is_valid.short_description = \"Company owner\"\n is_valid.admin_order_field = 'owner__last_name'\n\nThis module replaces the way of defining these attributes by providing a handy decorator.\n\n from django_admin_display import admin_display\n\n\n class Company(models.Model):\n ...\n\n @admin_display(\n short_description=\"Company owner\",\n admin_order_field='owner__last_name',\n )\n def owner(self) -> bool:\n return self.owner.last_name\n\n\n## Why?\n\nThere are mainly two reasons why this module exists.\n\n### Usage with `@property`\n\nIt is quite common that a calculated model property is displayed in the admin interface:\n\n class Company(models.Model):\n ...\n\n @property\n def created_on(self) -> datetime.date:\n return self.created_at.date()\n\nIn order to add special attributes, you have to create a protected method,\nattach the attributes and wrap that method using `property()`\n\n class Company(models.Model):\n ...\n\n def _created_on(self) -> datetime.date:\n return self.created_at.date()\n _created_on.short_description = \"Created on\"\n created_on = property(_created_on)\n\nThis is quite cumbersome, hard to read and most people don't know that this is even possible.\nTo overcome these downsides you can achieve the same result using the `@admin_diplay` decorator.\n\n from django_admin_display import admin_display\n\n\n class Company(models.Model):\n ...\n\n @property\n @admin_display(\n short_description = \"Created on\",\n )\n def created_on(self) -> datetime.date:\n return self.created_at.date()\n\n### mypy\n\nIf you are using [mypy](http://mypy-lang.org/), you have probably stumbled over an error similar to this one\n\n> \"Callable[[Any, Any], Any]\" has no attribute \"short_description\"\n\nA common solution is to ignore the type checking by adding `# type: ignore` to the end of the line.\n\n class CompanyAdmin(admin.ModelAdmin):\n ...\n\n def created_on(self, company: models.Company) -> datetime.date:\n return company.created_at.date()\n created_on.short_description = \"Created on\" # type: ignore\n\nThe issue is already known and heavily discussed on [github](https://github.com/python/mypy/issues/2087).\n\nThis decorator solves the issue by internally using `# type: ignore` and providing a well-defined signature for setting the attributes.\nIt is not an optimal solution but works well until the issue has been resolved.\n\n\n## Development\n\nThis project is using [poetry](https://poetry.eustace.io/) to manage all\ndev dependencies.\nClone this repository and run\n\n poetry install\n poetry run pip install Django\n\nto create a virtual environment with all dependencies.\nYou can now run the test suite using\n\n poetry run pytest\n\nThis repository follows the [angular commit conventions](https://github.com/marionebl/commitlint/tree/master/@commitlint/config-angular).\n", "description_content_type": "text/markdown", "docs_url": null, "download_url": "", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/escaped/django-admin-display", "keywords": "", "license": "BSD-3-Clause", "maintainer": "Alexander Frenzel", "maintainer_email": "alex@relatedworks.com", "name": "django-admin-display", "package_url": "https://pypi.org/project/django-admin-display/", "platform": "", "project_url": "https://pypi.org/project/django-admin-display/", "project_urls": { "Documentation": "https://github.com/escaped/django-admin-display/blob/master/README.md", "Homepage": "https://github.com/escaped/django-admin-display", "Repository": "https://github.com/escaped/django-admin-display" }, "release_url": "https://pypi.org/project/django-admin-display/1.1.0/", "requires_dist": null, "requires_python": ">=3.6", "summary": "Simplifies the use of function attributes for the django admin and makes mypy happy", "version": "1.1.0" }, "last_serial": 4835162, "releases": { "1.0.0": [ { "comment_text": "", "digests": { "md5": "8cbe049385c9197473cbdb499ee3321c", "sha256": "396271b35691ec0042cc45fa7125266012f36c07e33f77610be18ce1c47febf3" }, "downloads": -1, "filename": "django_admin_display-1.0.0-py3-none-any.whl", "has_sig": false, "md5_digest": "8cbe049385c9197473cbdb499ee3321c", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": ">=3.6", "size": 4737, "upload_time": "2019-02-12T18:34:29", "url": "https://files.pythonhosted.org/packages/27/96/02508244dd3d871320583b522e1af62541f4d43fd2f4828de8f9148b51b1/django_admin_display-1.0.0-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "ef270e1c4c049dc7bdf19e706f8cd8c5", "sha256": "ef5f6681fdfff733971d97fccf0cedf279861ebc29592412782549f018022328" }, "downloads": -1, "filename": "django-admin-display-1.0.0.tar.gz", "has_sig": false, "md5_digest": "ef270e1c4c049dc7bdf19e706f8cd8c5", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3.6", "size": 3003, "upload_time": "2019-02-12T18:34:26", "url": "https://files.pythonhosted.org/packages/ea/83/f0ce5dc988ce7c69e64c11dcd70d314e981e8169c453211e8b2a9e46b754/django-admin-display-1.0.0.tar.gz" } ], "1.1.0": [ { "comment_text": "", "digests": { "md5": "b9402cd8406fdc16180b778c0437ab64", "sha256": "86fc2dd2e6d9cc5c79275744b0f26711683a4a6a629e3397a6270f8c768b770a" }, "downloads": -1, "filename": "django_admin_display-1.1.0-py3-none-any.whl", "has_sig": false, "md5_digest": "b9402cd8406fdc16180b778c0437ab64", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": ">=3.6", "size": 6121, "upload_time": "2019-02-18T13:38:56", "url": "https://files.pythonhosted.org/packages/41/ba/15d1185a6f3f610f8745dd2d38c5b5bbcf73fe9231b54adddac8d28a630b/django_admin_display-1.1.0-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "0465897faea911b87d1653d4584b4014", "sha256": "5e5c82b2d80c80c013323d763c39ab031320bd0f929582cbc0fb5b52d144e597" }, "downloads": -1, "filename": "django-admin-display-1.1.0.tar.gz", "has_sig": false, "md5_digest": "0465897faea911b87d1653d4584b4014", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3.6", "size": 4620, "upload_time": "2019-02-18T13:38:55", "url": "https://files.pythonhosted.org/packages/fe/0b/4d7dfae4c7facf2baeea0c15bf0c2dcf02cbb4ec3fb3f5dfb772841865c8/django-admin-display-1.1.0.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "b9402cd8406fdc16180b778c0437ab64", "sha256": "86fc2dd2e6d9cc5c79275744b0f26711683a4a6a629e3397a6270f8c768b770a" }, "downloads": -1, "filename": "django_admin_display-1.1.0-py3-none-any.whl", "has_sig": false, "md5_digest": "b9402cd8406fdc16180b778c0437ab64", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": ">=3.6", "size": 6121, "upload_time": "2019-02-18T13:38:56", "url": "https://files.pythonhosted.org/packages/41/ba/15d1185a6f3f610f8745dd2d38c5b5bbcf73fe9231b54adddac8d28a630b/django_admin_display-1.1.0-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "0465897faea911b87d1653d4584b4014", "sha256": "5e5c82b2d80c80c013323d763c39ab031320bd0f929582cbc0fb5b52d144e597" }, "downloads": -1, "filename": "django-admin-display-1.1.0.tar.gz", "has_sig": false, "md5_digest": "0465897faea911b87d1653d4584b4014", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3.6", "size": 4620, "upload_time": "2019-02-18T13:38:55", "url": "https://files.pythonhosted.org/packages/fe/0b/4d7dfae4c7facf2baeea0c15bf0c2dcf02cbb4ec3fb3f5dfb772841865c8/django-admin-display-1.1.0.tar.gz" } ] }