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
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. For instance, you may use it if you have an Author model as ManyToMany relation in the Book model (Book.authors = ManyToManyField(Author)) and you want to have concatenated list of all authors coupled to a given book.
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
book = Book.objects.all() \
.values('id',
'title',
'pages',
'price',
'publisher__id',
'publisher__name') \
.annotate(
authors__name=GroupConcat('authors__name', separator=', ')
) \
.first()
Output would look as follows:
{
'authors__name': 'Finn Janssen, Dan Dijkman, Merel Wolf, Evy de Jong',
'id': 14,
'pages': 83,
'price': Decimal('62.13'),
'publisher__id': 19,
'publisher__name': 'Rijn, de Bruyn and Verharen',
'title': 'Laboriosam officia temporibus facere omnis odit.'
}
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.
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
Built Distribution
File details
Details for the file django-ormex-0.2.tar.gz
.
File metadata
- Download URL: django-ormex-0.2.tar.gz
- Upload date:
- Size: 23.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | ab5c8d6168a0a763c6a5cdd66adb1dc1bbf181614a501f739f5713afdc53d647 |
|
MD5 | 47e167952cba8fcbf1e8b012ba1a2e1b |
|
BLAKE2b-256 | c5c0406e03c968ed1b0aa8a7b0928171092d8ed54c1b8b5231b11cda32b184e4 |
File details
Details for the file django_ormex-0.2-py2.py3-none-any.whl
.
File metadata
- Download URL: django_ormex-0.2-py2.py3-none-any.whl
- Upload date:
- Size: 12.3 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8bc24b3387b403c31b24e9257ea217cfda405775037840cfd1c7bbded4a5f95e |
|
MD5 | 5c824a9111b257bc08608737ce2d8080 |
|
BLAKE2b-256 | 973e0b3057532576255072cfc5eb36ea819192c13875ab993666b4668f2ba885 |