A reusable Django app that allows adding dated decimal values to any Django model
Project description
A reusable Django app that allows adding dated decimal values to any Django model.
Installation
To get the latest stable release from PyPi
pip install django-dated-values
To get the latest commit from GitHub
pip install -e git+git://github.com/bitmazk/django-dated-values.git#egg=dated_values
TODO: Describe further installation steps (edit / remove the examples below):
Add dated_values to your INSTALLED_APPS
INSTALLED_APPS = (
...,
'dated_values',
)
Add the dated_values URLs to your urls.py
urlpatterns = patterns('',
...
url(r'^dated-values/', include('dated_values.urls')),
)
Don’t forget to migrate your database
./manage.py migrate dated_values
Add css or write your own custom styles.
{% load static %}
<link href="{% static "dated_values/css/dated_values.css" %}" rel="stylesheet">
Usage
The usage is fairly straight forward. You need to add DatedValueType instances for every content type, that you want values to be added to.
The decimal_places field allows you to lower the amount of decimal places for form validation. It defaults to 2 and its max is 8.
If you set hidden to True using the default template automatically hides the values in the form. You can e.g. use it to log values in the background without them being visible for users.
If you just set editable to True using the default template will render only the values and no input fields.
Once you’ve set that up and visit the management view, you will see a form table which holds all the values from all defined types for that item. The url kwargs require ctype_id and object_id. An example implementation might be:
class MyModel(models.Model):
... # my fields and other things go here
def get_management_url(self):
"""Returns the management url from django-dated-values."""
ctype = ContentType.objects.get_for_model(self.__class__)
return reverse('dated_values_management_view', kwargs={
'ctype_id': ctype.id, 'object_id': self.id})
Settings
The DATED_VALUES_ACCESS_ALLOWED setting expects a function, that takes the user and the content object as arguments. It is required to define the access permission for the values management view. Default is as follows:
DATED_VALUES_ACCESS_ALLOWED = lambda user, obj=None: user.is_staff
You can change the lenght of displayed items, defaulting to 14 (2 weeks) by setting DATED_VALUES_DISPLAYED_ITEMS:
# this will only show 1 week
DATED_VALUES_DISPLAYED_ITEMS = 7
Contribute
If you want to contribute to this project, please perform the following steps
# Fork this repository
# Clone your fork
mkvirtualenv -p python2.7 django-dated-values
make develop
git co -b feature_branch master
# Implement your feature and tests
git add . && git commit
git push -u origin feature_branch
# Send us a pull request for your feature branch
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
File details
Details for the file django-dated-values-0.2.tar.gz
.
File metadata
- Download URL: django-dated-values-0.2.tar.gz
- Upload date:
- Size: 16.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | cff4e25f1844b73839521d2a7fdb44dd1b8e77e263acafe27b563b7116ce3347 |
|
MD5 | cb2f7b8371d65cdfe46dbf86ffec9eda |
|
BLAKE2b-256 | 1f09550e28afcc59159e2a6ea3de06107feec5ab509069203248e3fde9b86b0e |