Statistic for django models
Project description
django-statistic
=========================
Statistic for models
Install
-------
For install you can use pip:
```
pip install django-statistic
```
Usage
-------
models.py
```
from django.db import models
class Authors(models.Model):
first_name = ....
last_name = ....
class Books(models.Model):
title = ....
author = models.ManyToManyField(Author)
```
views.py
```
from statistic import Statistic
from models import Authors, Books
def my_view(request):
book = Books.objects.get(...)
# Put object in statistic table
Statistic.objects.add(book)
# Get statistic for object
statistic_for_object = Statistic.objects.get_statistic_for_object(book)
# Get statistic for model
statistic_for_model = Statistic.objects.get_statistic_for_model(Books, limit=50)
# Get statistic for models
statistic_for_models = Statistic.objects.get_statistic_for_model([Authors, Books], limit=50, shuffle=True)
```
settings.py
```
RELATIVE_FOR_YEAR = 1 # Get relative year (Today is 2013, example get: 2012, 2013)
RELATIVE_FOR_MONTH = 3 # Get relative month (Today is 1'th January, example get: 2012.11, 2012.12, 2013.1)
RELATIVE_FOR_WEEK = 2 # Get relative week (Today is 13'th week of year, example get: 11, 12, 13 week of year)
```
Note
-------
For big data, you must use cache/crontab.
=========================
Statistic for models
Install
-------
For install you can use pip:
```
pip install django-statistic
```
Usage
-------
models.py
```
from django.db import models
class Authors(models.Model):
first_name = ....
last_name = ....
class Books(models.Model):
title = ....
author = models.ManyToManyField(Author)
```
views.py
```
from statistic import Statistic
from models import Authors, Books
def my_view(request):
book = Books.objects.get(...)
# Put object in statistic table
Statistic.objects.add(book)
# Get statistic for object
statistic_for_object = Statistic.objects.get_statistic_for_object(book)
# Get statistic for model
statistic_for_model = Statistic.objects.get_statistic_for_model(Books, limit=50)
# Get statistic for models
statistic_for_models = Statistic.objects.get_statistic_for_model([Authors, Books], limit=50, shuffle=True)
```
settings.py
```
RELATIVE_FOR_YEAR = 1 # Get relative year (Today is 2013, example get: 2012, 2013)
RELATIVE_FOR_MONTH = 3 # Get relative month (Today is 1'th January, example get: 2012.11, 2012.12, 2013.1)
RELATIVE_FOR_WEEK = 2 # Get relative week (Today is 13'th week of year, example get: 11, 12, 13 week of year)
```
Note
-------
For big data, you must use cache/crontab.
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
django-statistic-1.0.tar.gz
(3.9 kB
view details)
File details
Details for the file django-statistic-1.0.tar.gz
.
File metadata
- Download URL: django-statistic-1.0.tar.gz
- Upload date:
- Size: 3.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 742461b95baec130e3a40ea66089e837e119b3892f5b5d4520daf9bbc9a295f1 |
|
MD5 | 7f0e1b813b5eeefa695b532a7bee2f63 |
|
BLAKE2b-256 | c59f98de702a0a4574a313042423308581b5bddeae850c6b3515f09fa76349f2 |