django-reporting - Django Reporting System - Google Project Hosting
12693 단어 reporting
NOTE: django reporting is in beta version, what means that while working, it lacks a lot of features, and has not been well tested.
Introduction
Django Reporting System allows you to create dynamic reports for your models, consolidating and aggregating data, filtering and sorting it.
It requires Django 1.1, since it uses Django's ORM aggregation.
Add to exiting django project
settings.py
INSTALLED_APPS = (
[...]
'reporting',
'django.contrib.admin', # admin has to go before reporting in order to have links to the reports on the admin site
urs.py
from django.conf.urls.defaults import *
from django.contrib import admin
import reporting # import the module
admin.autodiscover()
reporting.autodiscover() # autodiscover reports in applications
urlpatterns = patterns('',
[...]
(r'^reporting/', include('reporting.urls')),
)
for more details see a 'samples' directory inside repository
Configure report
Let's say you have the follwing schema:
models.py:
class Department(models.Model):
[...]
class Occupation(models.Model):
[...]
class Person(models.Model):
name = models.CharField(max_length=255) # we won't use it in a summary report
occupation = models.ForeignKey(Occupation) # we'll be able to group and to filter by both occupation and country
department = models.ForeignKey(Department) # we'll be able to group and to filter by department and it leader
country = models.ForeignKey(Country)
birth_date = models.DateField() # we'll be able to filter by year
salary = models.DecimalField(max_digits=16, decimal_places=2) # we'll sum and calculate average for salary and expenses
expenses = models.DecimalField(max_digits=16, decimal_places=2)
in your application create a reports.py
reports.py:
import reporting
from django.db.models import Sum, Avg, Count
from models import Person
class PersonReport(reporting.Report):
model = Person
verbose_name = 'Person Report'
annotate = ( # Annotation fields (tupples of field, func, title)
('id', Count, 'Total'), # example of custom title for column
('salary', Sum), # no title - column will be "Salary Sum"
('expenses', Sum),
)
aggregate = ( # columns that will be aggregated (syntax the same as for annotate)
('id', Count, 'Total'),
('salary', Sum, 'Salary'),
('expenses', Sum, 'Expenses'),
)
group_by = [ # list of fields and lookups for group-by options
'department',
'department__leader',
'occupation',
]
list_filter = [ # This are report filter options (similar to django-admin)
'occupation',
'country',
]
detail_list_display = [ # if detail_list_display is defined user will be able to see how rows was grouped
'name',
'salary',
'expenses',
]
date_hierarchy = 'birth_date' # the same as django-admin
reporting.register('people', PersonReport) # Do not forget to 'register' your class in reports
for more details see a 'samples' projects inside repository
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
팟캐스트에서 브랜드에 대한 모든 언급 찾기이 게시물에서는 팟캐스트 에피소드에서 브랜드 언급을 확인하는 방법을 다룹니다. 팟캐스트 피드 URL, 시작/종료 날짜 및 브랜드 이름을 입력하면 스크립트는 Deepgram의 빠르고 정확한 음성 인식 API에서 감지한...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.