Skip to main content

Django ORM extensions

Project description

Django ORM extensions.

Prerequisites

  • Django 1.8, 1.9, 1.10, 1.11

  • Python 2.7, 3.4, 3.5, 3.6

Installation

  1. Install in your virtual environment

    Latest stable version from PyPI:

    pip install django-ormex

    Latest stable version from GitHub:

    pip install https://github.com/barseghyanartur/django-ormex/archive/stable.tar.gz

Usage

Common usage examples.

Aggregations

Contains various modules for aggregations.

GroupConcat

Works like Concat, but for concatenating field values of related ManyToMany model.

Given the following models:

class Publisher(models.Model):
    """Publisher."""

    name = models.CharField(max_length=30)
    address = models.CharField(max_length=50)
    city = models.CharField(max_length=60)
    state_province = models.CharField(max_length=30)
    country = models.CharField(max_length=50)
    website = models.URLField()


class Author(models.Model):
    """Author."""

    salutation = models.CharField(max_length=10)
    name = models.CharField(max_length=200)
    email = models.EmailField()
    headshot = models.ImageField(upload_to='authors', null=True, blank=True)


class Book(models.Model):
    """Book."""

    title = models.CharField(max_length=100)
    authors = models.ManyToManyField('books.Author', related_name='books')
    publisher = models.ForeignKey(Publisher, related_name='books')
    publication_date = models.DateField()
    isbn = models.CharField(max_length=100, unique=True)
    price = models.DecimalField(max_digits=10, decimal_places=2)
    pages = models.PositiveIntegerField(default=200)
    stock_count = models.PositiveIntegerField(default=30)

We could use GroupConcat as follows:

from ormex.aggregations import GroupConcat

books = Book.objects.all() \
        .select_related('publisher') \
        .prefetch_related('authors') \
        .only('id',
              'title',
              'pages',
              'price',
              'publisher__id',
              'publisher__name',
              'authors__id',
              'authors__name') \
        .values('id',
                'title',
                'pages',
                'price',
                'publisher__id',
                'publisher__name') \
        .annotate(authors__name=GroupConcat('authors__name')) \
        .distinct()

Demo

Run demo locally

In order to be able to quickly evaluate the django-ormex, a demo app (with a quick installer) has been created (works on Ubuntu/Debian, may work on other Linux systems as well, although not guaranteed). Follow the instructions below to have the demo running within a minute.

Grab the latest ormex_demo_installer.sh:

wget -O - https://raw.github.com/barseghyanartur/django-ormex/stable/examples/ormex_demo_installer.sh | bash

Open your browser and test the app.

If quick installer doesn’t work for you, see the manual steps on running the example project.

Testing

Simply type:

./runtests.py

or use tox:

tox

or use tox to check specific env:

tox -e py35

or run Django tests:

./manage.py test ormex --settings=settings.testing

License

GPL 2.0/LGPL 2.1

Support

For any issues contact me at the e-mail given in the Author section.

Author

Artur Barseghyan <artur.barseghyan@gmail.com>

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-ormex-0.1.tar.gz (9.1 MB view details)

Uploaded Source

Built Distribution

django_ormex-0.1-py2.py3-none-any.whl (9.1 MB view details)

Uploaded Python 2 Python 3

File details

Details for the file django-ormex-0.1.tar.gz.

File metadata

  • Download URL: django-ormex-0.1.tar.gz
  • Upload date:
  • Size: 9.1 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for django-ormex-0.1.tar.gz
Algorithm Hash digest
SHA256 bbe0e0e8d8e7f9429d9807fc294f5767f1820fcb719877895c58565e6e6ebaeb
MD5 55e13d1a6bc1a5245d80e82470d823f4
BLAKE2b-256 684212dc594fb30b02a937de4b079f17c3d4f24fb087c32fc491338ea2391fb4

See more details on using hashes here.

File details

Details for the file django_ormex-0.1-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for django_ormex-0.1-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 c391cb849c0c4254174a80bba00e69fe361d7a17bf6db32c3afb748104f2429c
MD5 d385dd56efa2b437cea91f759f3d527b
BLAKE2b-256 8dd4dc8654e54e96e2d36a87e4112b3ab43d20c17822fbc166ca3e0f279c0f30

See more details on using hashes here.

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