{
"info": {
"author": "Vincent Agnano",
"author_email": "vincent.agnano@scopyleft.fr",
"bugtrack_url": null,
"classifiers": [
"Environment :: Web Environment",
"Framework :: Django",
"Intended Audience :: Developers",
"License :: OSI Approved :: MIT License",
"Operating System :: OS Independent",
"Programming Language :: Python",
"Programming Language :: Python :: 2.7",
"Programming Language :: Python :: 3.4",
"Topic :: Utilities"
],
"description": "# Django Model URLs\r\n\r\n[](https://travis-ci.org/vinyll/django-model-urls)\r\n\r\nThis app makes urls usage DRYer.\r\nIt maps URL keywords to a model object instance by passing the object\r\ninstance as argument to the URL.\r\n\r\nIn short, having an `article` model instance, you can write this:\r\n\r\n```html\r\nView this article\r\n```\r\n\r\nWhile you have been writing this so far:\r\n\r\n```html\r\nView this article\r\n```\r\n\r\nThis is for your templates as well as for your `reverse()` and preserves\r\nother urls to work.\r\n\r\n> Right now it is build for [Jinja2](http://jinja.pocoo.org/) using the\r\neasy-to-use [Jingo](https://github.com/jbalogh/jingo) adapter.\r\n> If you are using plain Django template, refer to version 0.3.1.\r\n> A new version for plain Django should come out later on.\r\n\r\n\r\n## Installation\r\n\r\nDownload via pip \r\n\r\n```bash\r\npip install django-model-urls\r\n```\r\n\r\nor get the bleeding edge version:\r\n\r\n```bash\r\npip install git+https://github.com/vinyll/django-model-urls.git\r\n```\r\n\r\nAdd _model\\_urls_ to your _settings_ file:\r\n\r\n```python\r\nINSTALLED_APPS = (\r\n 'jingo',\r\n 'model_urls',\r\n)\r\n```\r\n\r\nAnd you're done!\r\n\r\n\r\n## How to use it\r\n\r\nIn the examples below we will consider this model:\r\n\r\n```python\r\nclass Article(models.Model):\r\n slug = models.SlugField()\r\n title = models.CharField(max_length=50)\r\n date = models.DateField()\r\n\r\n @property\r\n def year(self):\r\n return self.date.year\r\n\r\n @property\r\n def month(self):\r\n return self.date.month\r\n```\r\n\r\nand this urls:\r\n\r\n```python\r\nurlpatterns = patterns('',\r\n url(r'^article/(?P\\d{4})/(?P\\d{2})/(?P[\\w-]+)/$',\r\n ArticleView.as_view(), name=\"article_details\"),\r\n)\r\n```\r\n\r\nand `article` being an instance of the `Article` class.\r\n\r\n### In a template\r\n\r\n```python\r\nurl('article_details', article)\r\n```\r\n\r\n#### In a view\r\n\r\n```python\r\nfrom model_urls.urlresolvers import reverse\r\n\r\nreverse('article_details', article)\r\n```\r\n\r\nBoth will generate a url in this format:\r\n\r\n```\r\n/2014/11/how-to-optimize-django-urls/\r\n```\r\n\r\n## Extra tools\r\n\r\nBasically you should be able to use `url()` and `reverse()` in all cases.\r\nHowever, these tools are also available:\r\n\r\n\r\n#### Template helpers\r\n\r\n- `url(viewname, *args, **kwargs)` will try to detect an instance in arguments\r\nand choose wheter to use _simple\\_url()_ or _model\\_url()_ otherwise.\r\n- `simple_url(viewname, *args, **kwargs)` is an alias to Jingo's `url()`\r\nhelper to force using it.\r\n- `model_url(viewname, instance, *args, **kwargs)` will generate the url from\r\nthe instance in first argument.\r\n\r\n\r\n#### Url reversing\r\n\r\nThese functions are available in `model_urls.urlresolvers`.\r\n\r\n- `model_reverse(viewname, instance, urlconf=None, args=None, kwargs=None,\r\nprefix=None, current_app=None)` will generate the url based on the instance\r\nproperties.\r\n- `reverse(viewname, *args, **kwargs)` will fallback to _model\\_reverse()_ if\r\nan instance is found in arguments or to Django's _reverse()_ otherwise.\r\n\r\n\r\n## Configuration\r\n\r\nAn optional configuration is for your settings is:\r\n\r\n```python\r\nMODEL_URLS_HELPER_OVERRIDE = False\r\n```\r\n\r\nThis option will not allow the Jingo's `url()` helper to be overriden by the\r\none from model_urls.\r\n\r\nIn this case you should use `model_url()` to use an instance.\r\n\r\n\r\n\r\n### Further examples\r\n\r\n#### Use cases\r\n\r\nA common use case is switching from pk based url to slug.\r\nUsing django-model-urls means updating the _urls.py_ file to consider slug\r\nwithout altering views or template files.\r\n\r\n\r\n#### Read tests\r\n\r\nRefer to [tests.py](https://github.com/vinyll/django-model-urls/blob/master/model_urls/tests/)\r\nto see more usages.",
"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/vinyll/django-model-urls",
"keywords": "",
"license": "MIT",
"maintainer": "",
"maintainer_email": "",
"name": "django-model-urls",
"package_url": "https://pypi.org/project/django-model-urls/",
"platform": "UNKNOWN",
"project_url": "https://pypi.org/project/django-model-urls/",
"project_urls": {
"Download": "UNKNOWN",
"Homepage": "http://github.com/vinyll/django-model-urls"
},
"release_url": "https://pypi.org/project/django-model-urls/0.4.0/",
"requires_dist": null,
"requires_python": null,
"summary": "DRY way to manage url parameters associated with a model instance based on Jingo.",
"version": "0.4.0"
},
"last_serial": 1291186,
"releases": {
"0.3.1": [
{
"comment_text": "",
"digests": {
"md5": "afccbbe418bdf0f1be729d2c06009bf5",
"sha256": "7dc18df7f13334d5dd518924899618b0b5df21bff7b7ce55cfeefee51f9eccec"
},
"downloads": -1,
"filename": "django-model-urls-0.3.1.tar.gz",
"has_sig": false,
"md5_digest": "afccbbe418bdf0f1be729d2c06009bf5",
"packagetype": "sdist",
"python_version": "source",
"requires_python": null,
"size": 4366,
"upload_time": "2013-08-06T10:32:01",
"url": "https://files.pythonhosted.org/packages/bf/7b/2ed9cb726fba79c766a1ca1c3470808fbc200980762f5f6f5bb7f99a9961/django-model-urls-0.3.1.tar.gz"
}
],
"0.4.0": [
{
"comment_text": "",
"digests": {
"md5": "2bc38aa56876a02c68d76cdb77e59d2d",
"sha256": "596662071e17f67963a2cfa979c89c56824aed9e55b569d0460afbd9c5614cfa"
},
"downloads": -1,
"filename": "django-model-urls-0.4.0.tar.gz",
"has_sig": false,
"md5_digest": "2bc38aa56876a02c68d76cdb77e59d2d",
"packagetype": "sdist",
"python_version": "source",
"requires_python": null,
"size": 5911,
"upload_time": "2014-11-01T18:50:57",
"url": "https://files.pythonhosted.org/packages/ff/23/233f6d7e60bb978e312d5cb7cd17ab127195c8c9e01dc47e9f20bdbbbeba/django-model-urls-0.4.0.tar.gz"
}
]
},
"urls": [
{
"comment_text": "",
"digests": {
"md5": "2bc38aa56876a02c68d76cdb77e59d2d",
"sha256": "596662071e17f67963a2cfa979c89c56824aed9e55b569d0460afbd9c5614cfa"
},
"downloads": -1,
"filename": "django-model-urls-0.4.0.tar.gz",
"has_sig": false,
"md5_digest": "2bc38aa56876a02c68d76cdb77e59d2d",
"packagetype": "sdist",
"python_version": "source",
"requires_python": null,
"size": 5911,
"upload_time": "2014-11-01T18:50:57",
"url": "https://files.pythonhosted.org/packages/ff/23/233f6d7e60bb978e312d5cb7cd17ab127195c8c9e01dc47e9f20bdbbbeba/django-model-urls-0.4.0.tar.gz"
}
]
}