skip to navigation
skip to content

django-model-values 0.4

Taking the O out of ORM.

Package Documentation

Django model utilities for encouraging direct data access instead of unnecessary object overhead. Implemented through compatible method and operator extensions to QuerySets and Managers.

The goal is to provide elegant syntactic support for best practices in using Django’s ORM. Specifically avoiding the inefficiencies and race conditions associated with always using objects.

Usage

Typical model usage is verbose, inefficient, and incorrect.

book = Book.objects.get(pk=pk)
book.rating = 5.0
book.save()

The correct method is generally supported, but arguably less readable.

Book.objects.filter(pk=pk).update(rating=5.0)

model_values encourages the better approach with operator support.

Book.objects[pk]['rating'] = 5.0

Similarly for queries:

(book.rating for book in books)
books.values_list('rating', flat=True)
books['rating']

Column-oriented syntax is common in panel data layers, and the greater expressiveness cascades.

books.values_list('rating', flat=True).filter(rating__gt=0)
books['rating'] > 0

To enable, instantiate the custom Manager in your models. See documentation for more examples.

Installation

$ pip install django-model-values

Dependencies

  • Django 1.8+
  • Python 2.7, 3.3+

Tests

100% branch coverage.

$ py.test [--cov]

Changes

0.4

  • upsert method
  • django 1.9 database functions
  • bulk_update supports additional fields

0.3

  • Lookup methods and operators
  • F expressions and aggregation methods
  • Database functions
  • Conditional expressions for updates and annotations
  • Bulk updates and change detection

0.2

  • Change detection
  • Groupby functionality
  • Named tuples
 
File Type Py Version Uploaded on Size
django-model-values-0.4.tar.gz (md5) Source 2016-04-29 18KB