Taking the O out of ORM.
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.
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.
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.
$ pip install django-model-values
100% branch coverage.
$ py.test [--cov]