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. QuerySets also support aggregation and
conditionals.
books.values_list('rating', flat=True).filter(rating__gt=0)
books['rating'] > 0
books.aggregate(models.Avg('rating'))['rating__avg']
books['rating'].mean()
Managers provide a variety of efficient primary key based utilities.
To enable, instantiate the Manager in your models. As with any custom
Manager, it doesn't have to be named objects, but it is designed to
be a 100% compatible replacement.
from model_values import Manager
class Book(models.Model):
...
objects = Manager()
F expressions are also enhanced, and can be used directly without
model changes.
from model_values import F
.filter(rating__gt=0, last_modified__range=(start, end))
.filter(F.rating > 0, F.last_modified.range(start, end))
Installation
$ pip install django-model-values
Tests
100% branch coverage.
$ pytest [--cov]
Changes
1.0
- Update related methods moved with deprecation warnings
- Extensible change detection and updates
- Django 2.2 functions
0.6
- Transform functions
- Named tuples
- Window functions
- Distance lookups
- Django 2.1 functions
EnumField- Annotated
items - Expressions in column selection
0.5
Fexpressions operatorsanyandall- Spatial lookups and functions
- Django 2.0 support
0.4
upsertmethod- Django 1.9 database functions
bulk_updatesupports additional fields
0.3
- Lookup methods and operators
Fexpressions 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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file django-model-values-1.0.tar.gz.
File metadata
- Download URL: django-model-values-1.0.tar.gz
- Upload date:
- Size: 24.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.6.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
68ccc6198926bcc35504dcba72d830ec3c74347750189a5d24e8d8576be0a81d
|
|
| MD5 |
9365fe6a13cbabe846be1450293d49d4
|
|
| BLAKE2b-256 |
ac4cfb69397ab8385b6539b98a4deabac75f19a29a76b70ba677f8a771c79e47
|
File details
Details for the file django_model_values-1.0-py2.py3-none-any.whl.
File metadata
- Download URL: django_model_values-1.0-py2.py3-none-any.whl
- Upload date:
- Size: 10.3 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.6.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e7d89009b7beea5f8e549e4ba30281946680d9ebf01b740df3f88897dfe494d2
|
|
| MD5 |
249545eabf4cba17de3f88026593dd32
|
|
| BLAKE2b-256 |
c2cca33249067d99327b57a279f4b0989af2f34dd39f6bc9734316a8174a9ece
|