Skip to content

Commit

Permalink
docs: various minor improvements.
Browse files Browse the repository at this point in the history
  • Loading branch information
ngnpope committed Apr 6, 2021
1 parent 8b175ac commit 1673efe
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 20 deletions.
36 changes: 18 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,23 +23,23 @@ pip install django-admin-display
## Usage

If you want to change the behaviour of how Django displays a read-only value in the admin interface,
you 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.
you can add some [special attributes](https://docs.djangoproject.com/en/stable/ref/contrib/admin/#django.contrib.admin.ModelAdmin.list_display) to the corresponding method.
Supported values are

`short_description`
Customize the column’s title of the callable.
`short_description`
: Customize the column’s title of the callable.

`empty_value_display`
Show this value instead, if the value of a field is `None`, an empty string, or an iterable without elements.
`empty_value_display`
: Show this value instead, if the value of a field is `None`, an empty string, or an iterable without elements.

`admin_order_field`
Indicate that the value is represented by a certain database field.
`admin_order_field`
: Indicate that the value is represented by a certain database field.

`boolean`
Display a pretty “on” or “off” icon if the method returns a boolean.
`boolean`
: Display a pretty “on” or “off” icon if the method returns a boolean.

`allow_tags` (deprecated since Django 1.9)
Disable auto-escaping.
`allow_tags` _(Deprecated in Django 1.9, removed in 2.0)_
: Disable auto-escaping.

The following example shows, how you normally apply these attributes to an `AdminModel` or a `Model` method.

Expand All @@ -50,7 +50,7 @@ class Company(models.Model):
def owner(self) -> bool:
return self.owner.last_name
owner.short_description = "Company owner"
owner.admin_order_field = 'owner__last_name'
owner.admin_order_field = "owner__last_name"
```

This module replaces the way of defining these attributes by providing a handy decorator.
Expand All @@ -64,7 +64,7 @@ class Company(models.Model):

@admin_display(
short_description="Company owner",
admin_order_field='owner__last_name',
admin_order_field="owner__last_name",
)
def owner(self) -> bool:
return self.owner.last_name
Expand Down Expand Up @@ -112,7 +112,7 @@ class Company(models.Model):

@property
@admin_display(
short_description = "Created on",
short_description="Created on",
)
def created_on(self) -> datetime.date:
return self.created_at.date()
Expand All @@ -122,7 +122,7 @@ class Company(models.Model):

If you are using [mypy](http://mypy-lang.org/), you have probably stumbled over an error similar to this one

> "Callable[[Any, Any], Any]" has no attribute "short_description"
> `"Callable[[Any, Any], Any]" has no attribute "short_description"`
A common solution is to ignore the type checking by adding `# type: ignore` to the end of the line:

Expand All @@ -144,23 +144,23 @@ It is not an optimal solution but works well until the issue has been resolved.

This project uses [poetry](https://poetry.eustace.io/) for packaging and
managing all dependencies and [pre-commit](https://pre-commit.com/) to run
[flake8](http://flake8.pycqa.org/), [isort](https://pycqa.github.io/isort/),
[flake8](https://flake8.pycqa.org/), [isort](https://pycqa.github.io/isort/),
[mypy](http://mypy-lang.org/) and [black](https://github.com/python/black).

Additionally, [pdbpp](https://github.com/pdbpp/pdbpp) and [better-exceptions](https://github.com/qix-/better-exceptions) are installed to provide a better debugging experience.
To enable `better-exceptions` you have to run `export BETTER_EXCEPTIONS=1` in your current session/terminal.

Clone this repository and run

```bash
```sh
poetry install
poetry run pre-commit install
```

to create a virtual enviroment containing all dependencies.
Afterwards, you can run the test suite using

```bash
```sh
poetry run pytest
```

Expand Down
4 changes: 2 additions & 2 deletions django_admin_display/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

def admin_display(
admin_order_field: Optional[Union[str, BaseExpression]] = None,
allow_tags: Optional[bool] = None, # deprecated in django >= 2.0
allow_tags: Optional[bool] = None, # Deprecated in Django 1.9, removed in 2.0
boolean: Optional[bool] = None,
empty_value_display: Optional[str] = None,
short_description: Optional[str] = None,
Expand All @@ -25,7 +25,7 @@ def wrapper(func: Func) -> Func:
if allow_tags is not None:
if django.VERSION[:2] > (1, 11):
raise AttributeError(
"`allow_tags` is not supported by django > 2.0",
"`allow_tags` is not supported by django >= 2.0",
)
setattr(func, 'allow_tags', allow_tags)
if boolean is not None:
Expand Down

0 comments on commit 1673efe

Please sign in to comment.