{ "info": { "author": "Pavel Savchenko", "author_email": "pavel@modlinltd.com", "bugtrack_url": null, "classifiers": [ "Development Status :: 5 - Production/Stable", "Environment :: Web Environment", "Framework :: Django", "Framework :: Django :: 1.4", "Framework :: Django :: 1.5", "Framework :: Django :: 1.6", "Framework :: Django :: 1.7", "Intended Audience :: Developers", "License :: OSI Approved :: MIT License", "Programming Language :: Python", "Programming Language :: Python :: 2.7" ], "description": "ModelAdmin-Utils\r\n================\r\n\r\nA collection of useful Django ``admin.ModelAdmin`` mixins and template\r\ntags\r\n\r\nInstallation\r\n============\r\n\r\n::\r\n\r\n pip install Django-modeladmin-utils\r\n\r\nLimitInlinesAdminMixin\r\n======================\r\n\r\nIntro\r\n-----\r\n\r\nOccasionally, a relation to a specified object may include quite a few\r\nobject. In this case, a large list of inlines will be rendered, which\r\nmay not be desired.\r\n\r\nUsage\r\n~~~~~\r\n\r\nSimply add LimitInlinesAdminMixin to the parent ModelAdmin, and specify\r\nthe inlines to be limited in the attribute ``limit_inlines``. The number\r\nof entries shown is determined by ``settings.INLINES_MAX_LIMIT``\r\n(defaults to 15).\r\n\r\n::\r\n\r\n from modeladmin_utils.mixins import LimitInlinesAdminMixin\r\n\r\n # ...\r\n\r\n class SomeParentModelAdmin(LimitInlinesAdminMixin, admin.ModelAdmin):\r\n inlines = (MyRelationInline, AnotherRelativeInline)\r\n limit_inlines = (MyRelationInline, )\r\n\r\nTemplate: Link to \"show all\" entries\r\n------------------------------------\r\n\r\nAdditionally to limiting, you may also display in the header of the\r\ninline container a link to related object changelist, filtered by\r\nrelated entries only. This is achievable by the use of a ``templatetag``\r\nprovided in this package. Overriding the admin templates for the\r\nrelevant inline/s is easy:\r\n\r\n::\r\n\r\n {% link_to_changelist inline_admin_formset original as changelist_url %}\r\n {% if changelist_url %}\r\n  ({{inline_admin_formset.formset.limited_count}} / {{inline_admin_formset.formset.total_count}} displayed - {% trans \"Detailed View\" %})\r\n {% endif %}\r\n\r\nNotes\r\n-----\r\n\r\n1. To use the ``templatetag``, the app must be added to the\r\n ``settings.INSTALLED_APPS``:\r\n\r\n ::\r\n\r\n INSTALLED_APPS += (\r\n 'modeladmin_utils',\r\n )\r\n\r\n2. Examples of modified templates of both stacked and tabular inlines,\r\n based on Django 1.4 templates, are provided in this package (in\r\n ``templates/admin/edit_inlines``). However, these are not used by\r\n default to avoid confusion, to use them simply copy the template\r\n over, modify (see below in specific instructions) and set inline\r\n ``template`` attribute, e.g:\r\n\r\n ::\r\n\r\n class MyRelationInline(admin.TabularInline):\r\n template = 'path_to_your/templates/admin/edit_inlines/tabular.html'\r\n\r\n3. While the related model for the changelist is automatically\r\n determined, you may also specify an alternative model by specifying\r\n the ``unlimited_changelist_model`` attribute on the inline. This is\r\n useful if the inline is for a \"through model\" but the link should lead to\r\n the target model.\r\n\r\n ::\r\n\r\n class MyRelationInline(admin.TabularInline):\r\n unlimited_changelist_model = 'myapp.MyTargetModel'\r\n\r\nCustomizing template example\r\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~\r\n\r\nto add the link to a stacked template, copy over your original\r\ntemplates/admin/edit\\_inline/stacked.py, and place the code above in the\r\ndiv.tabular-header like so (note that I'm using a\r\n`django-grappelli `__ template here):\r\n\r\n::\r\n\r\n {% load modeladmin_links %}\r\n\r\n {# ... #}\r\n {% link_to_changelist inline_admin_formset original as changelist_url %}\r\n
\r\n

\r\n {% if inline_admin_formset.opts.title %}{{ inline_admin_formset.opts.title }}{% else %}{{ inline_admin_formset.opts.verbose_name_plural|capfirst }}{% endif %}\r\n {% if changelist_url %}\r\n  ({{inline_admin_formset.formset.limited_count}} / {{inline_admin_formset.formset.total_count}} displayed - {% trans \"Detailed View\" %})\r\n {% endif %}\r\n

\r\n {# ... #}\r\n\r\nAnd for stacked, use template templates/admin/edit\\_inline/stacked.py:\r\n\r\n::\r\n\r\n {% load modeladmin_links %}\r\n\r\n {# ... #}\r\n

\r\n {% if inline_admin_formset.opts.title %}\r\n {{ inline_admin_formset.opts.title }}\r\n {% else %}\r\n {{ inline_admin_formset.opts.verbose_name_plural|capfirst }}\r\n {% endif %}\r\n {% if changelist_url %}\r\n  ({{inline_admin_formset.formset.limited_count}} / {{inline_admin_formset.formset.total_count}} displayed - {% trans \"Detailed View\" %})\r\n {% endif %}\r\n

\r\n {# ... #}\r\n\r\nGenericSearchMixin\r\n==================\r\n\r\nIntro\r\n-----\r\n\r\nDjango allows the definition of GenericForeignKey but does not allow to\r\neasily query through them (joins). Hence, doing something like search\r\n\"through\" a Generic FK is anything but straightforward.\r\n\r\nEnter GenericSearchMixin!\r\n\r\nThis mixin overrides the ModelAdmin.get\\_search\\_results method to\r\nallow searching through a generic relation fields.\r\n\r\nFor quick set up, simply use a GenericForeignKey field name as the\r\nprefix in 'search\\_fields'.\r\n\r\nE.g: for a field named 'related\\_to' you can use the following:\r\nsearch\\_fields = ('related\\_to\\_\\_fname', 'related\\_to\\_\\_email', ...)\r\n\r\nOptionally, you may define 'related\\_search\\_mapping' in the ModelAdmin\r\nto explicitly define a generic field's object id and allowed content\r\ntypes (useful to limit the content types - faster query).\r\n\r\nExamples (see more in admin.py)\r\n-------------------------------\r\n\r\n::\r\n\r\n # find out pk and ctype fields using the virtual field\r\n related_search_mapping = {\r\n 'my_generic_fkey': {} \r\n }\r\n\r\n # the manual, \"define everything\" way\r\n related_search_mapping = {\r\n 'my_generic_fkey': {\r\n 'object_id': 'related_pk_field',\r\n 'ctypes': 'content_type_field'\r\n } \r\n }\r\n\r\nNotes\r\n-----\r\n\r\n- Required Django > 1.6\r\n- Currently, assumes id of related objects is unique across all models\r\n\r\nLocationMixin\r\n=============\r\n\r\n**Note:** Obsolete with newer Django versions\r\n\r\nIntro\r\n-----\r\n\r\nBefore Django 1.6 introduced\r\n`ModelAdmin.preserve\\_filters `__\r\nthe behavior of Django admin was as follows:\r\n\r\n1. filter a changelist by using search/filters\r\n2. click one of the result entries\r\n3. edit the result and save it\r\n4. Django redirects you to the changelist without storing your filters\r\n\r\nThis mixin introduces the ability to redirect the client back to the\r\nchangelist with the filters restored, after saving the change form.\r\n\r\nUsage\r\n-----\r\n\r\nSimply import LocationMixin and place it as a parent class on any\r\nModelAdmin sub-class, see TestLocationAdmin in admin.py for an example.", "description_content_type": null, "docs_url": null, "download_url": "UNKNOWN", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/modlinltd/ModelAdmin-Utils", "keywords": "django,mixin,modeladmin", "license": "MIT", "maintainer": "", "maintainer_email": "", "name": "django-modeladmin-utils", "package_url": "https://pypi.org/project/django-modeladmin-utils/", "platform": "UNKNOWN", "project_url": "https://pypi.org/project/django-modeladmin-utils/", "project_urls": { "Download": "UNKNOWN", "Homepage": "https://github.com/modlinltd/ModelAdmin-Utils" }, "release_url": "https://pypi.org/project/django-modeladmin-utils/1.0.0/", "requires_dist": null, "requires_python": null, "summary": "ModelAdmin utils", "version": "1.0.0" }, "last_serial": 1801422, "releases": { "1.0.0": [ { "comment_text": "", "digests": { "md5": "ae8be1024eb9aef776fef04d5676cc51", "sha256": "3eb4a3aeec87b26aea3534b6472ab0299f611fd565ad93d66af4aeb454fb099e" }, "downloads": -1, "filename": "django-modeladmin-utils-1.0.0.tar.gz", "has_sig": false, "md5_digest": "ae8be1024eb9aef776fef04d5676cc51", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 5234, "upload_time": "2015-11-04T20:22:44", "url": "https://files.pythonhosted.org/packages/8a/e0/6bc5fff5880e032e73bfec461c7d4f680c908ed5cd860ae28ee773eda422/django-modeladmin-utils-1.0.0.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "ae8be1024eb9aef776fef04d5676cc51", "sha256": "3eb4a3aeec87b26aea3534b6472ab0299f611fd565ad93d66af4aeb454fb099e" }, "downloads": -1, "filename": "django-modeladmin-utils-1.0.0.tar.gz", "has_sig": false, "md5_digest": "ae8be1024eb9aef776fef04d5676cc51", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 5234, "upload_time": "2015-11-04T20:22:44", "url": "https://files.pythonhosted.org/packages/8a/e0/6bc5fff5880e032e73bfec461c7d4f680c908ed5cd860ae28ee773eda422/django-modeladmin-utils-1.0.0.tar.gz" } ] }