.. image:: https://img.shields.io/pypi/v/django-slick-reporting.svg :target: https://pypi.org/project/django-slick-reporting
.. image:: https://img.shields.io/pypi/pyversions/django-slick-reporting.svg :target: https://pypi.org/project/django-slick-reporting
.. image:: https://img.shields.io/readthedocs/django-slick-reporting :target: https://django-slick-reporting.readthedocs.io/
.. image:: https://api.travis-ci.com/ra-systems/django-slick-reporting.svg?branch=master :target: https://app.travis-ci.com/github/ra-systems/django-slick-reporting
.. image:: https://img.shields.io/codecov/c/github/ra-systems/django-slick-reporting :target: https://codecov.io/gh/ra-systems/django-slick-reporting
一个功能齐全的报告引擎。
使用包管理器 pip <https://pip.pypa.io/en/stable/>_ 安装django-slick-reporting。
.. code-block:: console
pip install django-slick-reporting
假设我们有一个包含典型销售数据的模型SalesTransaction。
我们可以从该模型中提取不同种类的信息。
让我们从"分组"报告开始。这将生成一个报告,显示在特定时间内每种产品销售的数量和价值。
.. code-block:: python
# 在 views.py 中
from django.db.models import Sum
from slick_reporting.views import ReportView, Chart
from slick_reporting.fields import ComputationField
from .models import MySalesItems
class TotalProductSales(ReportView):
report_model = SalesTransaction
date_field = "date"
group_by = "product"
columns = [
"name",
ComputationField.create(
Sum, "quantity", verbose_name="总销售数量", is_summable=False
),
ComputationField.create(
Sum, "value", name="sum__value", verbose_name="总销售额 $"
),
]
chart_settings = [
Chart(
"总销售额 $",
Chart.BAR,
data_source=["sum__value"],
title_source=["name"],
),
Chart(
"总销售额 $ [饼图]",
Chart.PIE,
data_source=["sum__value"],
title_source=["name"],
),
]
# 然后,在 urls.py 中
path("total-sales-report", TotalProductSales.as_view())
使用这段代码,你将得到类似这样的结果:
.. image:: https://i.ibb.co/SvxTM23/Selection-294.png :target: https://i.ibb.co/SvxTM23/Selection-294.png :alt: 视图页面中的结果
时间序列报告是按时间段生成的报告。 时间段可以是每日、每周、每月、每年或自定义。计算将针对时间序列中的每个时间段执行。
示例:在一个日期范围内,每个产品每月的销售额是多少?
.. code-block:: python
# 在 views.py 中
from slick_reporting.views import ReportView
from slick_reporting.fields import ComputationField
from .models import SalesTransaction
class MonthlyProductSales(ReportView):
report_model = SalesTransaction
date_field = "date"
group_by = "product"
columns = ["name", "sku"]
time_series_pattern = "monthly"
# 或 "yearly"、"weekly"、"daily",以及其他自定义模式
time_series_columns = [
ComputationField.create(
Sum, "value", verbose_name=_("销售额"), name="value"
) # 每月将计算的内容
]
chart_settings = [
Chart(
_("月度总销售额"),
Chart.PIE,
data_source=["value"],
title_source=["name"],
plot_total=True,
),
Chart(
"总销售额 [面积图]",
Chart.AREA,
data_source=["value"],
title_source=["name"],
plot_total=False,
),
]
.. image:: https://github.com/ra-systems/django-slick-reporting/blob/develop/docs/source/topics/_static/timeseries.png?raw=true :alt: 时间序列报告 :align: center
使用交叉表报告(也称为矩阵报告)来显示三个或更多查询项之间的关系。 交叉表报告以行和列的形式显示数据,并在交叉点汇总信息。
.. code-block:: python
# 在 views.py 中
from slick_reporting.views import ReportView
from slick_reporting.fields import ComputationField
from .models import MySalesItems
class MyCrosstabReport(ReportView):
crosstab_field = "client"
crosstab_ids = [1, 2, 3]
crosstab_columns = [
ComputationField.create(Sum, "value", verbose_name=_("对应的值")),
]
crosstab_compute_remainder = True
columns = [
"some_optional_field",
# 你可以自定义交叉表列相对于其他列的显示位置
"__crosstab__",
# 这与交叉表中的计算相同,但这一列将计算整个集合的总值
ComputationField.create(Sum, "value", verbose_name=_("总值")),
]
.. image:: https://github.com/ra-systems/django-slick-reporting/blob/develop/docs/source/topics/_static/crosstab.png?raw=true :alt: 主页 :align: center
视图是ReportGenerator类的封装,这是报告引擎的核心。
您可以使用与ReportView相同的语法与ReportGenerator进行交互。
.. code-block:: python
from slick_reporting.generator import ReportGenerator
from .models import MySalesModel
class MyReport(ReportGenerator):
report_model = MySalesModel
group_by = "product"
columns = ["title", "__total__"]
# 或者
my_report = ReportGenerator(
report_model=MySalesModel, group_by="product", columns=["title", "__total__"]
)
my_report.get_report_data() # -> [{'title':'产品 1', '__total__: 56}, {'title':'产品 2', '__total__: 43}, ]
这只是您可以做的和自定义的一小部分。
可在 Django Slick Reporting <https://django-slick-reporting.com/>_ 上查看
您也可以在本地使用
.. code-block:: console
# 克隆仓库
git clone https://github.com/ra-systems/django-slick-reporting.git
# 创建虚拟环境并激活
python -m venv /path/to/new/virtual/environment
source /path/to/new/virtual/environment/bin/activate
cd django-slick-reporting/demo_proj
pip install -r requirements.txt
python manage.py migrate
python manage.py create_entries
python manage.py runserver
create_entries 命令将为演示应用生成数据
可在 Read The Docs <https://django-slick-reporting.readthedocs.io/en/latest/>_ 上查看
您可以在 本地运行文档
.. code-block:: console
<激活您的虚拟环境>
cd docs
pip install -r requirements.txt
sphinx-build -b html source build
创建一个虚拟环境(可以使用 virtual slick_reports_test),激活它;然后,
.. code-block:: console
$ git clone git+git@github.com:ra-systems/django-slick-reporting.git
$ cd tests
$ python -m pip install -e ..
$ python runtests.py
# 或者生成覆盖率报告
$ coverage run --include=../* runtests.py [-k]
$ coverage html
请考虑给项目加星以关注它。欢迎并需要您的PR和评审。
我们遵循格式良好的 Django 指南 <https://docs.djangoproject.com/en/dev/internals/contributing/writing-code/unit-tests/>_ 作为贡献指南。
RamezIssac <https://github.com/RamezIssac>_如果您喜欢这个包,您可能也会喜欢这些包!
Django Tabular Permissions <https://github.com/RamezIssac/django-tabular-permissions>_ 以可翻译和易于自定义的HTML表格形式显示Django权限。
Django ERP Framework <https://github.com/ra-systems/RA>_ 一个轻松构建业务解决方案的框架。
如果您觉得这个项目有用或前景广阔,可以通过给我们一个GitHub ⭐来支持我们


AI赋能电商视觉革命,一站式智能商拍平台
潮际好麦深耕服装行业,是国内AI试衣效果最好的软件。使用先进AIGC能力为电商卖家批量提供优质的、低成本的商拍图。合作品牌有Shein、Lazada、安踏、百丽等65个国内外头部品牌,以及国内10万+淘宝、天猫、京东等主流平台的品牌商家,为卖家节省将近85%的出图成本,提升约3倍出图效率,让品牌能够快速上架。


企业专属的AI法律顾问
iTerms是法大大集团旗下法律子品牌,基于最先进的大语言模型(LLM)、专业的法律知识库和强大的智能体架构,帮助企业扫清合规障碍,筑牢风控防线,成为您企业专属的AI法律顾问。


稳定高效的流量提升解决方案,助力品牌曝光
稳定高效的流量提升解决方案,助力品牌曝光


最新版Sora2模型免费使用,一键生成无水印视频
最新版Sora2模型免费使用,一键生成无水印视频


实时语音翻译/同声传译工具
Transly是一个多场景的AI大语言模型驱动的同声传译、专业翻译助手,它拥有超精准的音频识别翻译能力,几乎零延迟的使用体验和支持多国语言可以让你带它走遍全球,无论你是留学生、商务人士、韩剧美剧爱好者,还是出国游玩、多国会议、跨国追星等等,都可以满足你所有需要同传的场景需求,线上线下通用,扫除语言障碍,让全世界的语言交流不再有国界。


选题、配图、成文,一站式创作,让内容运营更高效
讯飞绘文,一个AI集成平台,支持写作、选题、配图、排版和发布。高效生成适用于各类媒体的定制内容,加速品牌传播,提升内容营销效果。


AI辅助编程,代码自动修复
Trae是一种自适应的集成开发环境(IDE),通过自动化和多元协作改变开发流程。利用Trae,团队能够更快速、精确地编写和部署代码,从而提高编程效率和项目交付速度。Trae具备上下文感知和代码自动完成功能,是提升开发效率的理想工具。


最强AI数据分析助手
小浣熊家族Raccoon,您的AI智能助手,致力于通过先进的人工智能技术,为用户提供高效、便捷的智能服务。无论是日常咨询还是专业问题解答,小浣熊都能以快速、准确的响应满足您的需求,让您的生活更加智能便捷。


像人一样思考的AI智能体
imini 是一款超级AI智能体,能根据人类指令,自主思考、自主完成、并且交付结果的AI智能体。


AI数字人视频创作平台
Keevx 一款开箱即用的AI数字人视频创作平台,广泛适用于电商广告、企业培训与社媒宣传,让全球企业与个人创作者无需拍摄剪辑,就能快速生成多语言、高质量的专业视频。
最新AI工具、AI资讯
独家AI资源、AI项目落地

微信扫一扫关注公众号