{ "info": { "author": "Akis Kesoglou", "author_email": "akiskesoglou@gmail.com", "bugtrack_url": null, "classifiers": [ "Development Status :: 4 - Beta", "Environment :: Web Environment", "Framework :: Django", "Intended Audience :: Developers", "License :: OSI Approved :: MIT License", "Operating System :: OS Independent", "Programming Language :: Python", "Programming Language :: Python :: 2", "Programming Language :: Python :: 2.6", "Programming Language :: Python :: 2.7", "Programming Language :: Python :: 3", "Programming Language :: Python :: 3.2", "Programming Language :: Python :: 3.3" ], "description": "django-connections\n^^^^^^^^^^^^^^^^^^\n\n.. image:: https://travis-ci.org/dfunckt/django-connections.svg?branch=master\n :target: https://travis-ci.org/dfunckt/django-connections\n.. image:: https://coveralls.io/repos/dfunckt/django-connections/badge.png?branch=master\n :target: https://coveralls.io/r/dfunckt/django-connections?branch=master\n\n``connections`` is a small app for Django that allows you to model any kind of\nrelationship between instances of *any* model. It's primary use is for\nbuilding a social graph that you can query and manage easily.\n\n\nRequirements\n============\n\n``connections`` requires Python 2.6/3.2 or newer and Django 1.5 or newer.\n\n\nHow to install\n==============\n\nUsing pip::\n\n $ pip install django-connections\n\nManually::\n\n $ git clone https://github.com/dfunckt/django-connections.git\n $ cd django-connections\n $ python setup.py install\n\n\nConfiguration\n=============\n\nAdd ``connections`` to your settings::\n\n INSTALLED_APPS = (\n # ...\n 'connections',\n )\n\nThen, run ``migrate``::\n\n $ python manage.py migrate\n\n**Note**: If you're running Django 1.6 or lower, you should run\n``manage.py syncdb`` instead.\n\n\nUsing ``connections``\n=====================\n\nWith ``connections`` you essentially build `directed graphs`_, where each\n*node* is a model instance and each *edge* is a ``Connection`` instance. Which\ntwo models a connection can connect, is determined by a ``Relationship``\ninstance that you predefine.\n\n.. _directed graphs: http://wikipedia.org/wiki/Directed_graph\n\n\nDefining relationships\n----------------------\n\nAssume you're *LitHub*, a social coding site in its infancy, and you need to\nlet your users star repositories they find interesting. With ``connections``,\nyou would first define a relationship::\n\n >>> from django.contrib.auth.models import User\n >>> from connections import define_relationship\n >>> from lithub.models import Repo\n >>> repo_stars = define_relationship('star_repo', from_model=User, to_model=Repo)\n\n``define_relationship`` creates and registers a new ``Relationship`` instance\nbetween the given models, with the name ``'star_repo'``. Names of\nrelationships must be unique across your project. You may alternatively\nspecify the models of the relationship as strings, e.g. ``'auth.User'`` or\n``'lithub.Repo'``.\n\nAny time you need to reference a relationship, you can either import the\nmodule variable (as defined above), or use ``connections.get_relationship(name)``.\n\n\nManaging connections\n--------------------\n\nLet's say that ``milo`` found a nice Python project on LitHub that he'd like\nto star, for future reference. In ``connections`` this can be modelled by\ncreating a connection between ``milo`` and the repository instance::\n\n >>> milo = User.objects.get(pk=104)\n >>> foopy = Repo.objects.get(pk=47)\n >>> star_repo.create_connection(milo, foopy)\n 'star_repo (auth.User:104 -> lithub.Repo:47)'\n\nConnections are unidirectional, meaning that if *foo* is connected with\n*bar*, the reverse -- that *bar* is connected to *foo* -- is *not* implied.\nIf you'd like to model a symmetrical relationship, that is, one that only\nmakes sense if both sides have agreed in the relationship (e.g. *friendship*\nor even *marriage*), you'd have to create two opposite connections, one for\neach side of the relationship.\n\nLet's see what repositories ``milo`` has starred::\n\n >>> repo_stars.connected_objects(milo)\n []\n\nWe can also query for the reverse, that is, what users have starred ``foopy``::\n\n >>> repo_stars.connected_to_objects(foopy)\n []\n\nThere are several other methods you may use to query or manage connections,\nthat you may read about in `API Reference`_.\n\n\nBest practices\n==============\n\nThe preferred idiom is to define relationships in ``app/relationships.py``\nfiles, keeping a module-global reference to each relationship instance,\nthrough which you manage connections between your model instances.\n\nIf you're using Django 1.7 or later you may have any ``relationships.py``\nmodules automatically imported at start-up::\n\n INSTALLED_APPS = (\n # ...\n 'connections.apps.AutodiscoverConnectionsConfig',\n )\n\n\nAPI Reference\n=============\n\n\nClass ``Relationship``\n----------------------\n\nRepresents a predefined type of connection between two nodes in a (directed)\ngraph. You may imagine relationships as the *kind* of an edge in the graph.\n::\n\n >>> from connections.models import Relationship\n >>> rel = Relationship('rel_name', from_content_type, to_content_type)\n\n\nInstance properties\n+++++++++++++++++++\n\n``connections``\n Returns a ``Connection`` query set matching all connections of this\n relationship.\n\n\nInstance methods\n++++++++++++++++\n\n``create_connection(from_obj, to_obj)``\n Creates and returns a new ``Connection`` instance between the given\n objects. If a connection already exists, the existing connection will be\n returned instead of creating a new one.\n\n``get_connection(from_obj, to_obj)``\n Returns a ``Connection`` instance for the given objects or ``None`` if\n there's no connection.\n\n``connection_exists(from_obj, to_obj)``\n Returns ``True`` if a connection between the given objects exists,\n else ``False``.\n\n``connections_from_object(from_obj)``\n Returns a ``Connection`` query set matching all connections with\n the given object as a source.\n\n``connections_to_object(to_obj)``\n Returns a ``Connection`` query set matching all connections with\n the given object as a destination.\n\n``connected_objects(from_obj)``\n Returns a query set matching all connected objects with the given\n object as a source.\n\n``connected_object_ids(from_obj)``\n Returns an iterable of the IDs of all objects connected with the given\n object as a source (i.e. the ``Connection.to_pk`` values).\n\n``connected_to_objects(to_obj)``\n Returns a query set matching all connected objects with the given\n object as a destination.\n\n``connected_to_object_ids(to_obj)``\n Returns an iterable of the IDs of all objects connected with the given\n object as a destination (i.e. the ``Connection.from_pk`` values).\n\n``distance_between(from_obj, to_obj, limit=2)``\n Calculates and returns an integer for the distance between two objects.\n A distance of *0* means ``from_obj`` and ``to_obj`` are the same\n objects, *1* means ``from_obj`` has a direct connection to ``to_obj``,\n *2* means that one or more of ``from_obj``'s connected objects are\n directly connected to ``to_obj``, and so on. ``limit`` limits the depth of\n connections traversal. Returns ``None`` if the two objects are not\n connected within ``limit`` distance.\n\n\nClass ``Connection``\n--------------------\n\nRepresents a connection between two nodes in the graph. Connections must\nbe treated as unidirectional, i.e. creating a connection from one node to\nanother should not imply the reverse.\n\n\nModel attributes\n++++++++++++++++\n\n``relationship_name``\n The name of the relationship. To access the relationship instance, use the\n ``Connection.relationship`` property.\n\n``from_pk``\n The primary key of the instance acting as source.\n\n``to_pk``\n The primary key of the instance acting as destination.\n\n``date``\n A ``datetime`` instance of the time the connection was created.\n\n\nInstance properties\n+++++++++++++++++++\n\n``relationship``\n Returns the ``Relationship`` instance the connection is about.\n\n``from_object``\n The source instance.\n\n``to_object``\n The destination instance.", "description_content_type": null, "docs_url": null, "download_url": "UNKNOWN", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "http://github.com/dfunckt/django-connections", "keywords": null, "license": "MIT", "maintainer": null, "maintainer_email": null, "name": "django-connections", "package_url": "https://pypi.org/project/django-connections/", "platform": "UNKNOWN", "project_url": "https://pypi.org/project/django-connections/", "project_urls": { "Download": "UNKNOWN", "Homepage": "http://github.com/dfunckt/django-connections" }, "release_url": "https://pypi.org/project/django-connections/0.1/", "requires_dist": null, "requires_python": null, "summary": "Create, query and manage graphs of relationships between your Django models", "version": "0.1" }, "last_serial": 1045507, "releases": { "0.1": [ { "comment_text": "", "digests": { "md5": "b82ec185b2cbe1157fa881aac6020a94", "sha256": "9354690e51505ec62c8a293e77ed04522986c9ea219ce2f2bc9c0c6974673d23" }, "downloads": -1, "filename": "django-connections-0.1.tar.gz", "has_sig": false, "md5_digest": "b82ec185b2cbe1157fa881aac6020a94", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 11200, "upload_time": "2014-03-29T19:12:46", "url": "https://files.pythonhosted.org/packages/33/b7/012124ecbe167bb725ae8b78c785e3e76e5b92108fe7aa40852e48e70b52/django-connections-0.1.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "b82ec185b2cbe1157fa881aac6020a94", "sha256": "9354690e51505ec62c8a293e77ed04522986c9ea219ce2f2bc9c0c6974673d23" }, "downloads": -1, "filename": "django-connections-0.1.tar.gz", "has_sig": false, "md5_digest": "b82ec185b2cbe1157fa881aac6020a94", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 11200, "upload_time": "2014-03-29T19:12:46", "url": "https://files.pythonhosted.org/packages/33/b7/012124ecbe167bb725ae8b78c785e3e76e5b92108fe7aa40852e48e70b52/django-connections-0.1.tar.gz" } ] }