Django Quick Reports

Quick Reports is very simple reporting tool that allows you to track the number of django model objects created each day.

Content

Installation

  1. Download it from PyPI

    pip install django-quick-reports

  2. Add quick_reports to your INSTALLED_APS setting.

INSTALLED_APPS = (
    ...
    'quick_reports',
)
  1. Add include('quick_reports.urls') to your url patterns.
urlpatterns = patterns('',
    ...
    url(r'^reports/', include('quick_reports.urls'))
)

Quickstart

After you install the package and update your settings and urls files, let create a simple report.

For example, you have an Article model and you’d like to know how many new articles created each day. Add QuickReport inner class to your model as below.

class Article(models.Model):
    class Status:
        DRAFT = 0
        PUBLISHED = 1
        CHOICES = [(DRAFT, "Draft"), (PUBLISHED, "Published")]

    title = models.CharField(max_length=190)
    body = models.TextField()
    slug = models.SlugField(max_length=190)
    status = models.IntegerField(choices=Status.CHOICES, default=Status.DRAFT)
    author = models.ForeignKey(User)
    created_at = models.DateTimeField(default=timezone.now)

    class QuickReport():
        date_field = "created_at"

Visit http://example.com/reports/ and find your model in left sidebar. If you click on that, you will see the chart similar to below

_images/sample_report1.png

QuickReport Model Fields

date_field

DateTimeField of your model which is set automatically when new object is created.

report_set

List of reports of a model. For each report in a model, you should define a unique name and a Q objects.

  • name: Unique report name of related model
  • query: Django Q objects.

For example,

class Article(models.Model):
    class Status:
        DRAFT = 0
        PUBLISHED = 1
        CHOICES = [(DRAFT, "Draft"), (PUBLISHED, "Published")]

    title = models.CharField(max_length=190)
    body = models.TextField()
    slug = models.SlugField(max_length=190)
    status = models.IntegerField(choices=Status.CHOICES, default=Status.DRAFT)
    author = models.ForeignKey(User)
    created_at = models.DateTimeField(default=timezone.now)

    class QuickReport():
        date_field = "created_at"
        report_set = (
            {
                "name": "Published",
                "query": Q(status=1)
            },
            {
                "name": "Drafts",
                "query": Q(status=0)
            },
        )
_images/sample_report2.png

License

The MIT License (MIT)

Copyright (c) 2015, Baris Bilgic

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Contact

Please get in touch with me for any questions.

baris [at] jooysoft.com

Indices and tables