{ "info": { "author": "Monwara LLC", "author_email": "branko@monwara.com", "bugtrack_url": null, "classifiers": [ "Development Status :: 2 - Pre-Alpha", "Environment :: Web Environment", "Framework :: Django", "Intended Audience :: Developers", "License :: OSI Approved :: BSD License" ], "description": "==============\ndjango-related\n==============\n\ndjango-related is a set of class-based-view mixins that help with common\nscenarios that involves related objects. The generic class-based views like\n``CreateView`` or ``UpdateView`` only deal with single objects. However, for\nnested resources, or in cases where we might want to use an existing object if\navaialble, these views lack functionality. This is what django-related\nprovides.\n\n.. contents::\n\nInstallation\n============\n\nInstallation can be done using pip::\n\n pip install django-related\n\nThere is no need to add ``related`` to installed apps. It can be used\ndirectly::\n \n from related.views import RedirectOnExistingMixin, CreateWithRelatedMixin\n ...\n\nGetExistingMixin\n================\n\nThis mixin is deprecated. It is currently just an alias for\nRedirectOnExistingMixin_ to provide backwards compatibility. It will be removed\nbecause of the confusing name.\n\nOnly the class name has changed. All property and method names are left intact.\n\n\nRedirectOnExistingMixin\n=======================\n\nThis mixin is used when an attempt to create an object that already exists in\nthe database should result in a redirect. If the object does not exist in the\ndatabase, it will not do anything.\n\nBasic usage::\n\n from related.views import RedirectOnExistingMixin\n from django.views.gneric import CreateView\n\n from models import Foo\n\n class MyView(RedirectOnExistingMixin, CreateView):\n model = Foo\n existing_redirect_url = '/bar'\n\nWith the above view, if we submit a form that contains a ``pk`` or ``slug``\nfield, and the ``Foo`` object with matching ``pk`` or ``slug`` field exists,\nuser will be redirected to ``/bar`` path, and the model form for ``Foo`` will\nnot even be processed. The redirect path can be customized using the options\ndiscussed further below.\n\nNote that this mixin _will_ result in extra database queries to determine\nwhether an object exists.\n\nThe view can be further customized using the following properties (and matching\nmethods):\n\n``existing_form_class`` (``get_existing_form_class()``)\n Uses the specified form to process the request rather than request\n parameters. Default is ``None`` (does no use forms).\n\n``existing_form_field``\n Form field that contains data about existence of the object. Note that this\n field does not need to evaluate to an actual object. Any non-``False``\n value will be treated as signifying object's existence. The most common use\n case is to use a ``ModelChoiceField`` or some field that reads the database\n in advance, and provides a choice of values that are only available when\n objects exist.\n\n``existing_form_initial`` (``get_existing_form_initial()``)\n Dictionary of initial values for the ``existing_form_class`` form (if form\n is used).\n\n``existing_pk_field``\n The model field that contains the primary key. Default is ``'pk'``.\n\n``existing_slug_field``\n The model field that contains the slug. Default is ``'slug'``\n\n``existing_request_pk_key``\n The request parameter that represents the primary key. Default is ``'pk'``.\n\n``existing_request_slug_key``\n The request parameter that represents the slug. Note that if primary key is\n specified (it is by default), and it is passed in request, slug will not be\n looked up.\n\n``existing_redirect_url`` (``get_existing_redirect_url()``)\n Required attribute. The URL that client will be redirected to if the object\n exists.\n\n``existing_form_name`` (``get_existing_form_name``)\n Customizes the name of the context object containing the form.\n\nRelatedObjectMixin\n===============\n\nThis mixin is a generic related object pre-fetching mixin. Before resorting to\nusing this mixin, let's first discuss an approach that works well without the\noverhead of ``RelatedObjectMixin``, in cases where you are only fetching the\nrelated object, but doing nothing else. Consider this URL pattern::\n\n /posts/(?P\\d+)/comments\n\n(Yes, there is a whole comment system included in Django, so, sorry for the\ncorny example.) In the above case You would normally use a list view for the\ncomments. But you might also want to fetch the post object as well. There is no\nneed to use ``RelatedObjectMixin`` in this particular case, because you can\ncombine Django's built-in ``SingleObjectMixin`` with ``ListView`` to achieve\nwhat you want.\n\nAnother case where you *do not* want to use this mixin is if you can fetch the\nrelated object using Django's DB API. For example, if you have a ``book``\nobject, you can probably get the related author as ``book.author``.\n\nThis mixin is useful only if you need two physically unrelated objects (like\nusing two ``SingleObjectMixin`` mixins in a view). If there is no actual\nrelationship between the two objects via a foreign key, then you should use\nthis mixin.\n\nFor users of the previous versions of django-related, it has to be noted that\nthis mixin is simply ripped out of what used to be a monolithic\nCreateWithRelatedMixin_. It therefore behaves more or less the same as that\nmixin.\n\nHere is an example::\n\n from related import RelatedObjectMixin\n from django.views.detail import SingleObjectMixin\n from django.views import FormView\n\n from cards.models import Card\n from cards.forms import MatchCardsForm\n\n # view for `/match/(?P\\d+)/(?\\d+)/`\n\n class ViewAttachment(RelatedObjectMixin, SingleObjectMixin, FormView):\n model = Card\n related_model = Card\n pk_url_kwarg = 'first_card_pk'\n related_pk_url_kwarg = 'second_card_pk'\n form_class = MatchCardsForm\n template_name = 'attachment.html'\n success_url = '/foo'\n\n def get_initial(self):\n return {\n 'first_card': self.object.pk,\n 'second_card': self.related_object.pk,\n }\n\n def form_valid(self, form):\n # Do something with the form, etc\n\nNote that naming of properties is basically cloned from the\n``SingleObjectMixin``, with a ``related_`` prefix. In most cases, you can guess\nthe properties you need to set if you know what they are called in\n``SingleObjectMixin``.\n\n``RelatedObjectMixin`` is currently limited to fetching only one object, just\nlike ``SingleObjectMixin``, and is therefore not suitable for complex nested\nstructures. Again, using Django's DB API would be more reasonable in many of\nthose cases.\n\nThe view can be customized using the following attributes (and matching\nmethods):\n\n``related_model``\n Related model under which the current model is nested. This attribute is\n required.\n\n``related_404_redirect_url`` (``get_related_404_url()``)\n If specified, the view will redirect instead of raising\n ``django.http.Http404`` or returning ``django.http.HttpResponseGone``. \n Default is ``None``.\n\n``related_404_message`` (``get_rlated_404_message()``)\n If ``related_404_redirect_url`` is used, the ``django.contrib.messages`` is\n used to display an error message. This attribute is used to customize this\n message. Default is ``'%s does not exist'`` where ``'%s'`` will evaluate to\n the ``related_model``'s verbose name.\n \n``related_pk_field``\n The field on the ``related_model`` that contains the primary key. Defaults\n to ``'pk'``.\n\n``related_pk_url_kwarg``\n The URL parameter that contains the primary key. Defaults to ``'pk'``.\n\n``related_slug_field``\n The field on the ``related_model`` that contains the sulug field. Defaults\n to ``'slug'``.\n\n``related_slug_url_kwarg``\n The URL parameter that contains the slug field. Defaults to ``'slug'``.\n\n``related_object_name`` (``get_related_object_name()``)\n Customizes name of the context object that contains the related object.\n\n``cache_backend`` (``get_cache_backend``)\n Specifies the object that implements the caching methods. This object is\n ``django.core.caching.cache`` by default. Any interface that you specify\n must provide the same methods as the default one.\n\nCreateWithRelatedMixin\n======================\n\nThis mixin is used when we are dealing with a ``CreateView`` for a nested\nresource. The main assumption is that higher levels of the path contains a slug\nor pk that points to the related model's object.\n\nAs discussed in the RelatedObjectMixin_ section, this mixin is based on it, so\nthe same customization options are available.\n\nThe key difference between normal CreateView (which can be persuaded to give\nyou the related object using the ``queryset`` attribute and ``get_object``\nmethod) and this mixin, lies in the form processing. This mixin does two things\ndifferently:\n\n1. It ensures that the related object exists (behavior similar to\n ``get_object`` is forced)\n2. It attaches the related object to the appropriate field in the submitted\n form.\n\nHere is an example::\n\n from related import CreateWithRelatedMixin\n from django.views import CreateView\n\n from models import Attachment, Post\n from forms import CustomAttachmentModelForm\n\n\n # View for `/posts/(?P[\\w-]+)/attachments`\n\n class AttachmentCreateView(CreateWithRelatedMixin, CreateView):\n model = Attachment\n form_class = CustomAttachmentModelForm\n related_model = Post\n\nWith the above setup, the ``django.http.Http404`` is raised if GET request is\nmade to this view with the slug in the URL that points to a non-existent post.\nIf POST request is made to the same URL, ``django.http.HttpResponseGone`` (410)\nis returned if post does not exist. Otherwise, the ``CustomAttachmentModelForm``\nis processed, and the ``Post`` object that was found based on the slug will be\nadded to ``post`` field of the object resulting from the form processing.\n\nThe view can be customized using the following attributes (and matching\nmethods):\n\n``related_model``\n Related model under which the current model is nested. This attribute is\n required.\n\n``related_field``\n Field on the current model that must point to the related object. By\n default, lower-cased ``related_model``'s class name (e.g., ``'foo'`` for a\n model called ``Foo``).\n\n``related_404_redirect_url`` (``get_related_404_url()``)\n If specified, the view will redirect instead of raising\n ``django.http.Http404`` or returning ``django.http.HttpResponseGone``. \n Default is ``None``.\n\n``related_404_message`` (``get_rlated_404_message()``)\n If ``related_404_redirect_url`` is used, the ``django.contrib.messages`` is\n used to display an error message. This attribute is used to customize this\n message. Default is ``'%s does not exist'`` where ``'%s'`` will evaluate to\n the ``related_model``'s verbose name.\n \n``related_pk_field``\n The field on the ``related_model`` that contains the primary key. Defaults\n to ``'pk'``.\n\n``related_pk_url_kwarg``\n The URL parameter that contains the primary key. Defaults to ``'pk'``.\n\n``related_slug_field``\n The field on the ``related_model`` that contains the sulug field. Defaults\n to ``'slug'``.\n\n``related_slug_url_kwarg``\n The URL parameter that contains the slug field. Defaults to ``'slug'``.\n\n``related_object_name`` (``get_related_object_name()``)\n Customizes name of the context object that contains the related object.\n\n``integritiy_error_message`` (``get_integrity_error_message()``)\n If there is an integrity error saving the object pointing to the related\n object, the view will rerender the form, but will also add an error message\n to the response object using ``django.contrib.messages``. This attribute\n customizes the message. Default is ``'Such record already exists'``.\n\n``cache_backend`` (``get_cache_backend``)\n Specifies the object that implements the caching methods. This object is\n ``django.core.caching.cache`` by default. Any interface that you specify\n must provide the same methods as the default one.\n\nReporting bugs\n==============\n\nPlease report bugs and feature requests to the Bitbucket `issue tracker`_.\n\n.. _issue tracker: https://bitbucket.org/monwara/django-related/issues", "description_content_type": null, "docs_url": null, "download_url": "https://bitbucket.org/monwara/django-related/downloads", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://bitbucket.org/monwara/django-related", "keywords": null, "license": "BSD", "maintainer": null, "maintainer_email": null, "name": "django-related", "package_url": "https://pypi.org/project/django-related/", "platform": "UNKNOWN", "project_url": "https://pypi.org/project/django-related/", "project_urls": { "Download": "https://bitbucket.org/monwara/django-related/downloads", "Homepage": "https://bitbucket.org/monwara/django-related" }, "release_url": "https://pypi.org/project/django-related/0.0.6/", "requires_dist": null, "requires_python": null, "summary": "Class-based-views mixins for handling related objects", "version": "0.0.6" }, "last_serial": 619107, "releases": { "0.0.1": [ { "comment_text": "", "digests": { "md5": "f417c463065912b7386c9243f75969ff", "sha256": "61648012591329a24262dd071a62a0c3ba4d2f123930d04109fbf87214910135" }, "downloads": -1, "filename": "django-related-0.0.1.tar.gz", "has_sig": false, "md5_digest": "f417c463065912b7386c9243f75969ff", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 5239, "upload_time": "2012-11-21T16:26:50", "url": "https://files.pythonhosted.org/packages/69/3e/aa57dd3c0f46a1ba5f7dfc883eb45d593dded0cffb6b7339bc4f8fb9cfe9/django-related-0.0.1.tar.gz" }, { "comment_text": "", "digests": { "md5": "6932ae5b080e4afd140efec64e0a275c", "sha256": "df695c72ea21721fc5118f2210301a583377a17985aebef3641fa066ee8498b1" }, "downloads": -1, "filename": "django-related-0.0.1.zip", "has_sig": false, "md5_digest": "6932ae5b080e4afd140efec64e0a275c", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 7846, "upload_time": "2012-11-21T16:26:57", "url": "https://files.pythonhosted.org/packages/41/ab/b7d161a4f469560f0bf27b51a25697cdeadc58eed10d23dbbd973bc9f128/django-related-0.0.1.zip" } ], "0.0.2": [ { "comment_text": "", "digests": { "md5": "b50545ff5b8f02532c55f5ac8f3fd5ac", "sha256": "0d0d4ea173aae96244f0aa0bf5ffb4574dd6b6040a05cb64fcc912b20443a763" }, "downloads": -1, "filename": "django-related-0.0.2.tar.gz", "has_sig": false, "md5_digest": "b50545ff5b8f02532c55f5ac8f3fd5ac", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 5385, "upload_time": "2012-11-21T21:08:39", "url": "https://files.pythonhosted.org/packages/f2/97/e575eb7edf6744e41891ecc9c16529f57bd44b52e330eb760bb9700fa3cd/django-related-0.0.2.tar.gz" }, { "comment_text": "", "digests": { "md5": "9d86bdc192b3294c3949b0f0af02bd14", "sha256": "f1b41920862a535df1cf77188769ca122c631db5848065698a4cc4888bd3ffe0" }, "downloads": -1, "filename": "django-related-0.0.2.zip", "has_sig": false, "md5_digest": "9d86bdc192b3294c3949b0f0af02bd14", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 8039, "upload_time": "2012-11-21T21:08:48", "url": "https://files.pythonhosted.org/packages/d1/c6/80d42e9e702a1b9bdf33bd4810a75356ba5ca874836e895edb0983a6a82e/django-related-0.0.2.zip" } ], "0.0.3": [ { "comment_text": "", "digests": { "md5": "ba7e68f6d9365e0db62a143d33fef503", "sha256": "31ba1334d053c90a7c1e015204debd8ca40b91bae8fbc8ac9a04450f25aa53e5" }, "downloads": -1, "filename": "django-related-0.0.3.tar.gz", "has_sig": false, "md5_digest": "ba7e68f6d9365e0db62a143d33fef503", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 6409, "upload_time": "2012-11-23T23:18:48", "url": "https://files.pythonhosted.org/packages/88/a8/a6415650698a435867dfb418af7078241fe70b358a6af02a4f8306944606/django-related-0.0.3.tar.gz" }, { "comment_text": "", "digests": { "md5": "8d219e34f5660d5c7a8d966790ca4d23", "sha256": "99e9456f9133e7f38485eb21c7058b281608108509ead8055f5c2444e1e47540" }, "downloads": -1, "filename": "django-related-0.0.3.zip", "has_sig": false, "md5_digest": "8d219e34f5660d5c7a8d966790ca4d23", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 9401, "upload_time": "2012-11-23T23:18:57", "url": "https://files.pythonhosted.org/packages/dc/a6/760029178c8b421144ff7e8c6e8f7f5149be290425868220e0a0a4739322/django-related-0.0.3.zip" } ], "0.0.4": [ { "comment_text": "", "digests": { "md5": "0618ec79e088453f06460be16ecb5dff", "sha256": "f0d51edae6f3c3674bb3b08b80498a9a056637a666c9ff784bc3d5b2829b8460" }, "downloads": -1, "filename": "django-related-0.0.4.tar.gz", "has_sig": false, "md5_digest": "0618ec79e088453f06460be16ecb5dff", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 6468, "upload_time": "2013-02-27T21:16:27", "url": "https://files.pythonhosted.org/packages/1b/52/7eb60a843de308f49e2f50c1b814268d2d2ecc918cedc0d97513f323c3aa/django-related-0.0.4.tar.gz" }, { "comment_text": "", "digests": { "md5": "361d7b4120e347c35e69c17307666be2", "sha256": "faa383f3aa8b504299c788a223ae6dfcddea328b7b4b640ed8d7162feff8bc3f" }, "downloads": -1, "filename": "django-related-0.0.4.zip", "has_sig": false, "md5_digest": "361d7b4120e347c35e69c17307666be2", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 9491, "upload_time": "2013-02-27T21:16:48", "url": "https://files.pythonhosted.org/packages/e0/ca/0ea2d354a2cbdf6be47db5bf6f6c8bcec178f08f3734511f7ee798d1955f/django-related-0.0.4.zip" } ], "0.0.5": [ { "comment_text": "", "digests": { "md5": "ac53f39de89ec68f80f414252eb4fc78", "sha256": "f06eedaf2b3ca0250d567e34e459535ab46eecd474e4b68b39104d85846d9106" }, "downloads": -1, "filename": "django-related-0.0.5.tar.gz", "has_sig": false, "md5_digest": "ac53f39de89ec68f80f414252eb4fc78", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 8417, "upload_time": "2013-04-26T14:33:16", "url": "https://files.pythonhosted.org/packages/ec/65/06593c4e63e9f83662ecf98aca755afb9e7a2278584c99b02223b857af01/django-related-0.0.5.tar.gz" }, { "comment_text": "", "digests": { "md5": "4e8be17e34f7b24ecf98bfd2e238e7c6", "sha256": "e5664921c2e11aa5036d71664435af2ef8b80bdc07adcc62211445e82a1efde7" }, "downloads": -1, "filename": "django-related-0.0.5.zip", "has_sig": false, "md5_digest": "4e8be17e34f7b24ecf98bfd2e238e7c6", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 12236, "upload_time": "2013-04-26T14:33:24", "url": "https://files.pythonhosted.org/packages/3e/6a/909d35a97668133aa1435735cce51858cf2411e1aee4079029882c793db8/django-related-0.0.5.zip" } ], "0.0.6": [ { "comment_text": "", "digests": { "md5": "86475d49c17df15bec3db394b4f98c84", "sha256": "487db00ef8c9daac602087de47a77cca18bc326431b6212b387f2eabc873992d" }, "downloads": -1, "filename": "django-related-0.0.6.tar.gz", "has_sig": false, "md5_digest": "86475d49c17df15bec3db394b4f98c84", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 8491, "upload_time": "2013-04-26T19:28:37", "url": "https://files.pythonhosted.org/packages/59/f0/1fb679e6eb0edbf4a38a573cdd63f4611e63b76629dbeb3c137df21e4e1c/django-related-0.0.6.tar.gz" }, { "comment_text": "", "digests": { "md5": "2638d75933f82b5013427e548b24fbb8", "sha256": "1e91eceb612111d135da3717d719934f6d873d79146a4f8823f1d205c02cdd67" }, "downloads": -1, "filename": "django-related-0.0.6.zip", "has_sig": false, "md5_digest": "2638d75933f82b5013427e548b24fbb8", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 12325, "upload_time": "2013-04-26T19:28:45", "url": "https://files.pythonhosted.org/packages/8b/af/9747475973915ef956779bd1b9f7dc64f07a89c3a70c11cc436c710c0ba8/django-related-0.0.6.zip" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "86475d49c17df15bec3db394b4f98c84", "sha256": "487db00ef8c9daac602087de47a77cca18bc326431b6212b387f2eabc873992d" }, "downloads": -1, "filename": "django-related-0.0.6.tar.gz", "has_sig": false, "md5_digest": "86475d49c17df15bec3db394b4f98c84", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 8491, "upload_time": "2013-04-26T19:28:37", "url": "https://files.pythonhosted.org/packages/59/f0/1fb679e6eb0edbf4a38a573cdd63f4611e63b76629dbeb3c137df21e4e1c/django-related-0.0.6.tar.gz" }, { "comment_text": "", "digests": { "md5": "2638d75933f82b5013427e548b24fbb8", "sha256": "1e91eceb612111d135da3717d719934f6d873d79146a4f8823f1d205c02cdd67" }, "downloads": -1, "filename": "django-related-0.0.6.zip", "has_sig": false, "md5_digest": "2638d75933f82b5013427e548b24fbb8", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 12325, "upload_time": "2013-04-26T19:28:45", "url": "https://files.pythonhosted.org/packages/8b/af/9747475973915ef956779bd1b9f7dc64f07a89c3a70c11cc436c710c0ba8/django-related-0.0.6.zip" } ] }