Skip to main content

image image image image image build image CodeQL image ty

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]

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

django_model_values-1.8.tar.gz (14.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

django_model_values-1.8-py3-none-any.whl (10.6 kB view details)

Uploaded Python 3

File details

Details for the file django_model_values-1.8.tar.gz.

File metadata

  • Download URL: django_model_values-1.8.tar.gz
  • Upload date:
  • Size: 14.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.14

File hashes

Hashes for django_model_values-1.8.tar.gz
Algorithm Hash digest
SHA256 ff019e52021fe0ada220833e616b972ab59dde11aa580a20f737e7bfe061c0d2
MD5 938f3915d13abad3535ceea393b9d46e
BLAKE2b-256 ac2c125196790bb83d462f47cd03695b2735b2c539d9606105a09ab7c2345d23

See more details on using hashes here.

Provenance

The following attestation bundles were made for django_model_values-1.8.tar.gz:

Publisher: release.yml on coady/django-model-values

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file django_model_values-1.8-py3-none-any.whl.

File metadata

File hashes

Hashes for django_model_values-1.8-py3-none-any.whl
Algorithm Hash digest
SHA256 0113175aefb2c3c8f9ad261c0bba11382bf561a1751db28675ff2a511d599fd7
MD5 13804dc66da451d3a32d17b344a0c23b
BLAKE2b-256 07f0a2729454d40cb122b4dd67ef371fa2bccc6bc34e1c6a520bb539c1e6532e

See more details on using hashes here.

Provenance

The following attestation bundles were made for django_model_values-1.8-py3-none-any.whl:

Publisher: release.yml on coady/django-model-values

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page