brechin / django-computed-property

Computed Property Fields for Django

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Coverage Status Build Status

django-computed-property

Computed Property Fields for Django

Inspired by Google Cloud Datastore NDB Computed Properties.

Automatically store a computed value in the database when saving your model so you can filter on values requiring complex (or simple!) calculations.

Quick start

  1. Install this library

    pip install django-computed-property
    
  2. Add to INSTALLED_APPS

    INSTALLED_APPS = [
        ...,
        'computed_property'
    ]
  3. Add a computed field to your model(s)

    from django.db import models
    import computed_property
    
    class MyModel(models.Model):
        doubled = computed_property.ComputedIntegerField(compute_from='double_it')
        base = models.IntegerField()
     
        def double_it(self):
            return self.base * 2

Documentation available at http://django-computed-property.readthedocs.io/en/latest/

About

Computed Property Fields for Django

License:MIT License


Languages

Language:Python 99.7%Language:Makefile 0.3%