{ "info": { "author": "Pawel Scierski", "author_email": "escer@protonmail.com", "bugtrack_url": null, "classifiers": [ "Development Status :: 3 - Alpha", "Environment :: Web Environment", "Framework :: Django :: 1.10", "Framework :: Django :: 1.8", "Framework :: Django :: 1.9", "Intended Audience :: Developers", "License :: OSI Approved :: MIT License", "Operating System :: OS Independent", "Programming Language :: Python :: 2", "Programming Language :: Python :: 2.7", "Programming Language :: Python :: 3", "Programming Language :: Python :: 3.4", "Programming Language :: Python :: 3.5", "Topic :: Internet :: WWW/HTTP" ], "description": "django-collectionfield\n======================\n\n.. image:: https://api.travis-ci.org/escer/django-collectionfield.svg?branch=master\n :target: https://travis-ci.org/escer/django-collectionfield\n.. image:: https://img.shields.io/pypi/v/django-collectionfield.svg\n :target: https://pypi.python.org/pypi/django-collectionfield\n.. image:: https://coveralls.io/repos/github/escer/django-collectionfield/badge.svg?branch=master\n :target: https://coveralls.io/github/escer/django-collectionfield?branch=master\n\nA reusable Django model field to store collections.\n\nFeatures\n--------\n\n- highly configurable **model field** (changing collection and item types, sorting, choices, item uniqueness and more)\n- **custom lookups** to simplify queries over collection items\n- **form fields** for working with collections\n- collection **item validators**\n- extended ``get_FIELD_display`` method for model fields with choices\n- works with database backends without native support for multi-value columns (like ArrayField for PostgreSQL)\n\nInstallation\n------------\n\n.. code-block:: python\n\n pip install django-collectionfield\n\n\nUsage\n-----\n\nModel field\n~~~~~~~~~~~\n\nDefine model with field that stores lists of strings:\n\n.. code-block:: python\n\n # models.py\n from django.db import models\n from collectionfield.models import CollectionField\n\n class MyModel(models.Model):\n tags = CollectionField()\n\nPass values to model field:\n\n.. code-block:: python\n\n my_model = MyModel.objects.create(tags=['test', 'values'])\n my_model.values\n ['test', 'values']\n\nMaking queries\n~~~~~~~~~~~~~~\n\nRetrieve model instances with particular value present in the collection:\n\n.. code-block:: python\n\n MyModel.objects.filter(tags__has='test')\n\nRetrieve model instances with *ALL* values present in the collection (ignoring items' order):\n\n.. code-block:: python\n\n MyModel.objects.filter(tags__hasall=['test', 'values'])\n\nRetrieve model instances with *ANY* of values present in the collection:\n\n.. code-block:: python\n\n MyModel.objects.filter(tags__hasany=['test', 'values'])\n\n\nCustomizing collections\n~~~~~~~~~~~~~~~~~~~~~~~\n\nCustom collection and item type:\n\n.. code-block:: python\n\n class IntegerSet(models.Model):\n # This field will provide sets of integers \n # instead of default lists of strings:\n values = CollectionField(collection_type=set, item_type=int)\n\nSorting and uniqueness:\n\n.. code-block:: python\n\n class SortedUniqueTextList(models.Model):\n # Before saving, items will be sorted and duplicates dropped:\n texts = CollectionField(sort=True, unique_items=True)\n\nChoices and collection size limit:\n\n.. code-block:: python\n\n class TaggedModel(models.Model):\n tags = CollectionField(\n # Both choices and max_items limit are checked during model validation.\n choices=(\n ('action', \"Action\"),\n ('comedy', \"Comedy\"),\n ('horror', \"Horror\"),\n # ...\n ),\n max_items=2\n )\n\n``get_FIELD_display`` method can handle multiple choices and provide options to customize the display:\n\n.. code-block:: python\n\n tagged_model = TaggedModel.objects.create(tags=['action', 'horror'])\n tagged_model.get_tags_display()\n \"Action, Horror\"\n\n def li_mapper(value, label):\n return \"