Taking the O out of ORM.
Project description
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
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-model-values-0.4.tar.gz
.
File metadata
- Download URL: django-model-values-0.4.tar.gz
- Upload date:
- Size: 19.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 50641289752c855eff69798d2caaeef92e232a23600466412de18d806052b580 |
|
MD5 | 9962fb8ecc46241eee540f3f229d4958 |
|
BLAKE2b-256 | c07b60edfe86b12022298a42576cfe98319a93481791fc5d555866c545000bea |