[![image](https://img.shields.io/pypi/v/django-model-values.svg)](https://pypi.org/project/django-model-values/)
![image](https://img.shields.io/pypi/pyversions/django-model-values.svg)
![image](https://img.shields.io/pypi/djversions/django-model-values.svg)
[![image](https://pepy.tech/badge/django-model-values)](https://pepy.tech/project/django-model-values)
![image](https://img.shields.io/pypi/status/django-model-values.svg)
[![image](https://github.com/coady/django-model-values/workflows/build/badge.svg)](https://github.com/coady/django-model-values/actions)
[![image](https://codecov.io/gh/coady/django-model-values/branch/main/graph/badge.svg)](https://codecov.io/gh/coady/django-model-values/)
[![image](https://github.com/coady/django-model-values/workflows/codeql/badge.svg)](https://github.com/coady/django-model-values/security/code-scanning)
[![image](https://img.shields.io/badge/code%20style-black-000000.svg)](https://pypi.org/project/black/)
[![image](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/v2.json)](https://github.com/astral-sh/ruff)
[![image](https://mypy-lang.org/static/mypy_badge.svg)](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]
```
Raw data
{
"_id": null,
"home_page": "",
"name": "django-model-values",
"maintainer": "",
"docs_url": "https://pythonhosted.org/django-model-values/",
"requires_python": ">=3.8",
"maintainer_email": "",
"keywords": "values_list,pandas,column-oriented,data,mapper,pattern,orm",
"author": "",
"author_email": "Aric Coady <aric.coady@gmail.com>",
"download_url": "https://files.pythonhosted.org/packages/47/21/c4013e109311a33358bd18b6024b525d5b66f800174617fafc8eb2b33f35/django-model-values-1.6.tar.gz",
"platform": null,
"description": "[![image](https://img.shields.io/pypi/v/django-model-values.svg)](https://pypi.org/project/django-model-values/)\n![image](https://img.shields.io/pypi/pyversions/django-model-values.svg)\n![image](https://img.shields.io/pypi/djversions/django-model-values.svg)\n[![image](https://pepy.tech/badge/django-model-values)](https://pepy.tech/project/django-model-values)\n![image](https://img.shields.io/pypi/status/django-model-values.svg)\n[![image](https://github.com/coady/django-model-values/workflows/build/badge.svg)](https://github.com/coady/django-model-values/actions)\n[![image](https://codecov.io/gh/coady/django-model-values/branch/main/graph/badge.svg)](https://codecov.io/gh/coady/django-model-values/)\n[![image](https://github.com/coady/django-model-values/workflows/codeql/badge.svg)](https://github.com/coady/django-model-values/security/code-scanning)\n[![image](https://img.shields.io/badge/code%20style-black-000000.svg)](https://pypi.org/project/black/)\n[![image](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/v2.json)](https://github.com/astral-sh/ruff)\n[![image](https://mypy-lang.org/static/mypy_badge.svg)](https://mypy-lang.org/)\n\n[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`.\n\nThe 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.\n\n## Usage\nTypical model usage is verbose, inefficient, and incorrect.\n\n```python\nbook = Book.objects.get(pk=pk)\nbook.rating = 5.0\nbook.save()\n```\n\nThe correct method is generally supported, but arguably less readable.\n\n```python\nBook.objects.filter(pk=pk).update(rating=5.0)\n```\n\n`model_values` encourages the better approach with operator support.\n\n```python\nBook.objects[pk]['rating'] = 5.0\n```\n\nSimilarly for queries:\n\n```python\n(book.rating for book in books)\nbooks.values_list('rating', flat=True)\nbooks['rating']\n```\n\nColumn-oriented syntax is common in panel data layers, and the greater expressiveness cascades. `QuerySets` also support aggregation and conditionals.\n\n```python\nbooks.values_list('rating', flat=True).filter(rating__gt=0)\nbooks['rating'] > 0\n\nbooks.aggregate(models.Avg('rating'))['rating__avg']\nbooks['rating'].mean()\n```\n\n`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.\n\n```python\nfrom model_values import Manager\n\nclass Book(models.Model):\n ...\n objects = Manager()\n```\n\n`F` expressions are also enhanced, and can be used directly without model changes.\n\n```python\nfrom model_values import F\n\n.filter(rating__gt=0, last_modified__range=(start, end))\n.filter(F.rating > 0, F.last_modified.range(start, end))\n```\n\n## Installation\n```console\n% pip install django-model-values\n```\n\n## Tests\n100% branch coverage.\n\n```console\n% pytest [--cov]\n```\n",
"bugtrack_url": null,
"license": "Copyright 2022 Aric Coady Licensed under the Apache License, Version 2.0 (the \"License\"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. ",
"summary": "Taking the O out of ORM.",
"version": "1.6",
"project_urls": {
"Changelog": "https://github.com/coady/django-model-values/blob/main/CHANGELOG.md",
"Documentation": "https://coady.github.io/django-model-values",
"Homepage": "https://github.com/coady/django-model-values",
"Issues": "https://github.com/coady/django-model-values/issues"
},
"split_keywords": [
"values_list",
"pandas",
"column-oriented",
"data",
"mapper",
"pattern",
"orm"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "d7f09a0ad5da75fa28ccd0c4b7d00776ac06631b9a04582c73dd2a416e7a6a27",
"md5": "68b87c8114eb3ff6b60f9f0ceeb50998",
"sha256": "ba6a7454f6a7a0d4c1fdf5526919e91bdcb1c4591cf1afffd096ea5cf08bf4ca"
},
"downloads": -1,
"filename": "django_model_values-1.6-py3-none-any.whl",
"has_sig": false,
"md5_digest": "68b87c8114eb3ff6b60f9f0ceeb50998",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.8",
"size": 10780,
"upload_time": "2023-11-04T17:01:56",
"upload_time_iso_8601": "2023-11-04T17:01:56.809603Z",
"url": "https://files.pythonhosted.org/packages/d7/f0/9a0ad5da75fa28ccd0c4b7d00776ac06631b9a04582c73dd2a416e7a6a27/django_model_values-1.6-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "4721c4013e109311a33358bd18b6024b525d5b66f800174617fafc8eb2b33f35",
"md5": "6be525d4bfd4c62678617a34831fe918",
"sha256": "fde8d8d9f9b9d624e38ba8b7f906826cccc7d0a4a0953ca58931df33070e9cd0"
},
"downloads": -1,
"filename": "django-model-values-1.6.tar.gz",
"has_sig": false,
"md5_digest": "6be525d4bfd4c62678617a34831fe918",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.8",
"size": 10698,
"upload_time": "2023-11-04T17:01:58",
"upload_time_iso_8601": "2023-11-04T17:01:58.113230Z",
"url": "https://files.pythonhosted.org/packages/47/21/c4013e109311a33358bd18b6024b525d5b66f800174617fafc8eb2b33f35/django-model-values-1.6.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2023-11-04 17:01:58",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "coady",
"github_project": "django-model-values",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"lcname": "django-model-values"
}