This is a pre-production deployment of Warehouse, however changes made here WILL affect the production instance of PyPI.
Latest Version Dependencies status unknown Test status unknown Test coverage unknown
Project Description
Django-compoundqueryset
------------

|PyPi|

.. |PyPi| image:: https://badge.fury.io/py/django-compoundqueryset.svg
:target: https://pypi.python.org/pypi/django-compoundqueryset

A little Django app allows for compound querysets between different tables.
Especially useful for pagination of said results.



Django versions supported: 1.8, 1.9, 1.10

Python versions supported: 2.7, 3.3, 3.4, 3.5



Installation
------------

You can obtain the source code for ``django-compoundqueryset`` from here:

::

https://github.com/brianwawok/django-compoundqueryset


Using `pip`:

pip install django-compoundqueryset

Motivation
-----------

Sometimes you might want to combine two different tables with similar fields and show them to users. For example:

.. code:: python

from django.db import models



class FirstModel(models.Model):
age = models.IntegerField()
name = models.TextField(max_length=100)
color = models.TextField(max_length=100)


class SecondModel(models.Model):
age = models.IntegerField()
name = models.TextField(max_length=100)
size = models.IntegerField()


And you want to paginate across them

.. code:: python

from django.core.paginator import Paginator
from djcompoundqueryset import CompoundQueryset


qs_1 = FirstModel.objects.order_by('age').all()
qs_2 = SecondModel.objects.order_by('age').all()
combined_queryset = qs_1 | qs_2

p = Paginator(combined_queryset, 10)

You will get the dreaded error

Merging 'QuerySet' classes must involve the same values in each case.

Now with django-compoundqueryset, you can do:

.. code:: python

from django.core.paginator import Paginator
from djcompoundqueryset import CompoundQueryset


qs_1 = FirstModel.objects.order_by('age').all()
qs_2 = SecondModel.objects.order_by('age').all()
combined_queryset = CompoundQueryset(qs_1, qs_2, max_items=100)

p = Paginator(combined_queryset, 10)

You can now iterate over these models in a view, showing the age. Max_items says you will
never use more than that many items, so limit the count a queries. Useful if you have
capped pagination.


Performance
-----------
The goal is to beat the naive implementation (load all records into memory and deal with there), but
we may not beat a RawSQL union all monster. If performance is really important you may need to do that.

If used in a Django Paginator, we will normally do 1 count(*) query per queryset, and then only load the
required records.
Release History

Release History

0.1.3

This version

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

0.1.2

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

0.1.1

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

0.1

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

Download Files

Download Files

TODO: Brief introduction on what you do with files - including link to relevant help section.

File Name & Checksum SHA256 Checksum Help Version File Type Upload Date
django-compoundqueryset-0.1.3.zip (7.0 kB) Copy SHA256 Checksum SHA256 Source Aug 2, 2016

Supported By

WebFaction WebFaction Technical Writing Elastic Elastic Search Pingdom Pingdom Monitoring Dyn Dyn DNS HPE HPE Development Sentry Sentry Error Logging CloudAMQP CloudAMQP RabbitMQ Heroku Heroku PaaS Kabu Creative Kabu Creative UX & Design Fastly Fastly CDN DigiCert DigiCert EV Certificate Rackspace Rackspace Cloud Servers DreamHost DreamHost Log Hosting