Django Admin Totals, add totals to your columns in Django admin.
Project description
# Django Admin Totals
Module to show totals in Django Admin List.
[![codecov](https://codecov.io/gh/douwevandermeij/admin-totals/branch/master/graph/badge.svg)](https://codecov.io/gh/douwevandermeij/admin-totals)
[![Build Status](https://travis-ci.org/douwevandermeij/admin-totals.svg?branch=master)](https://travis-ci.org/douwevandermeij/admin-totals)
## Installation
virtualenv .
source bin/activate
pip install git+https://github.com/douwevandermeij/admin-totals.git
## Usage
In settings.py
INSTALLED_APPS = [
'admin_totals',
]
In admin.py:
from admin_totals.admin import ModelAdminTotals
from django.contrib import admin
from django.db.models import Sum, Avg
from django.db.models.functions import Coalesce
@admin.register(MyModel)
class MyModelAdmin(ModelAdminTotals):
list_display = ['col_a', 'col_b', 'col_c']
list_totals = [('col_b', lambda field: Coalesce(Sum(field), 0))), ('col_c', Avg)]
Make sure to at least have the columns of `list_totals` in `list_display`.
## Tests
python runtests.py
## Contributing
Please make sure to run the following commands before pushing and making a PR:
pip install -r requirements/test-ci.txt
isort --recursive admin_totals tests
flake8 tests admin_totals
`isort` will sort the imports and `flake8` will lint the code. Please fix any errors before committing. Also, make sure to write passing tests.
Module to show totals in Django Admin List.
[![codecov](https://codecov.io/gh/douwevandermeij/admin-totals/branch/master/graph/badge.svg)](https://codecov.io/gh/douwevandermeij/admin-totals)
[![Build Status](https://travis-ci.org/douwevandermeij/admin-totals.svg?branch=master)](https://travis-ci.org/douwevandermeij/admin-totals)
## Installation
virtualenv .
source bin/activate
pip install git+https://github.com/douwevandermeij/admin-totals.git
## Usage
In settings.py
INSTALLED_APPS = [
'admin_totals',
]
In admin.py:
from admin_totals.admin import ModelAdminTotals
from django.contrib import admin
from django.db.models import Sum, Avg
from django.db.models.functions import Coalesce
@admin.register(MyModel)
class MyModelAdmin(ModelAdminTotals):
list_display = ['col_a', 'col_b', 'col_c']
list_totals = [('col_b', lambda field: Coalesce(Sum(field), 0))), ('col_c', Avg)]
Make sure to at least have the columns of `list_totals` in `list_display`.
## Tests
python runtests.py
## Contributing
Please make sure to run the following commands before pushing and making a PR:
pip install -r requirements/test-ci.txt
isort --recursive admin_totals tests
flake8 tests admin_totals
`isort` will sort the imports and `flake8` will lint the code. Please fix any errors before committing. Also, make sure to write passing tests.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
admin-totals-1.0.tar.gz
(5.9 kB
view hashes)
Built Distributions
admin_totals-1.0-py3-none-any.whl
(25.1 kB
view hashes)
admin_totals-1.0-py2-none-any.whl
(25.0 kB
view hashes)
Close
Hashes for admin_totals-1.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 78d0a39c1091ac28ddc5301dee50af2bdb6783ba0296ccf96ce98f07e2cf95fd |
|
MD5 | dedf8877264b758b623748134429512f |
|
BLAKE2b-256 | 9181182ee933b06566dae274cced9368e94a1ea8a3cfd5f54f5217e42496e785 |
Close
Hashes for admin_totals-1.0-py2-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 82e88b9a6d603a8bb0963763db4bef16364ddf028838e63c5fbecc961303b5ea |
|
MD5 | f365a5fdf88d8899e39ca220b5854a69 |
|
BLAKE2b-256 | 8ac4c174540fac6a37ab88af9aefa41fec9dd5591227e4dc6c5f15c8ffd83226 |