Skip to main content

Taking the O out of ORM.

Project description

https://img.shields.io/pypi/v/django-model-values.svg https://img.shields.io/pypi/pyversions/django-model-values.svg https://img.shields.io/pypi/status/django-model-values.svg https://img.shields.io/travis/coady/django-model-values.svg https://img.shields.io/codecov/c/github/coady/django-model-values.svg

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


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-0.4.tar.gz (19.2 kB view hashes)

Uploaded Source

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page