https://github.com/coady/django-model-values
Taking the O out of ORM.
https://github.com/coady/django-model-values
column-oriented data-mapper django models orm pandas
Last synced: 10 months ago
JSON representation
Taking the O out of ORM.
- Host: GitHub
- URL: https://github.com/coady/django-model-values
- Owner: coady
- License: other
- Created: 2015-09-20T02:34:12.000Z (over 10 years ago)
- Default Branch: main
- Last Pushed: 2025-01-16T22:45:20.000Z (about 1 year ago)
- Last Synced: 2025-03-29T17:06:06.329Z (11 months ago)
- Topics: column-oriented, data-mapper, django, models, orm, pandas
- Language: Python
- Homepage: https://coady.github.io/django-model-values
- Size: 1.01 MB
- Stars: 68
- Watchers: 6
- Forks: 3
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE.txt
Awesome Lists containing this project
README
[](https://pypi.org/project/django-model-values/)


[](https://pepy.tech/project/django-model-values)

[](https://github.com/coady/django-model-values/actions/workflows/build.yml)
[](https://codecov.io/gh/coady/django-model-values/)
[](https://github.com/coady/django-model-values/actions/workflows/github-code-scanning/codeql)
[](https://github.com/astral-sh/ruff)
[](https://mypy-lang.org/)
[Django](https://docs.djangoproject.com) 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.
```python
book = Book.objects.get(pk=pk)
book.rating = 5.0
book.save()
```
The correct method is generally supported, but arguably less readable.
```python
Book.objects.filter(pk=pk).update(rating=5.0)
```
`model_values` encourages the better approach with operator support.
```python
Book.objects[pk]['rating'] = 5.0
```
Similarly for queries:
```python
(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.
```python
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.
```python
from model_values import Manager
class Book(models.Model):
...
objects = Manager()
```
`F` expressions are also enhanced, and can be used directly without model changes.
```python
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
```console
% pip install django-model-values
```
## Tests
100% branch coverage.
```console
% pytest [--cov]
```