Skip to main content

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

django-dated-values-0.2.tar.gz (16.4 kB view hashes)

Uploaded Source

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page