{"id":283,"date":"2014-06-14T02:41:36","date_gmt":"2014-06-14T02:41:36","guid":{"rendered":"http:\/\/www.ramandv.com\/blog\/?p=283"},"modified":"2014-06-18T06:55:19","modified_gmt":"2014-06-18T06:55:19","slug":"django-autocomplete_light-admin-interface-integration","status":"publish","type":"post","link":"http:\/\/www.ramandv.com\/blog\/django-autocomplete_light-admin-interface-integration\/","title":{"rendered":"Django autocomplete_light and admin interface integration"},"content":{"rendered":"\n<!-- Quick Adsense WordPress Plugin: http:\/\/quickadsense.com\/ -->\n<div class=\"e9e85ee105af8a6a4a383deebf1fa216\" data-index=\"1\" style=\"float: none; margin:10px 0 10px 0; text-align:center;\">\n<script type=\"text\/javascript\"><!--\r\ngoogle_ad_client = \"ca-pub-4917982260456644\";\r\n\/* ramandv.com-ad1 *\/\r\ngoogle_ad_slot = \"9226290554\";\r\ngoogle_ad_width = 728;\r\ngoogle_ad_height = 90;\r\n\/\/-->\r\n<\/script>\r\n<script type=\"text\/javascript\"\r\nsrc=\"http:\/\/pagead2.googlesyndication.com\/pagead\/show_ads.js\">\r\n<\/script>\n<\/div>\n<p>I just wanted to enable autocomplete in my admin interface. It took almost 3 hours to understand whats happening and to make it work, because for integrating in admin interface, the docs is not very clear.<\/p>\n<p>You need to read the docs first<\/p>\n<p>http:\/\/django-autocomplete-light.readthedocs.org\/en\/latest\/quick.html<\/p>\n<p>And the read this<\/p>\n<p>Scenario:<\/p>\n<pre><code>class A(models.Model):\n    fieldA1 = models.CharField()\n    fieldA2 = models.CharField()\n\nclass B(models.Model):\n    fieldB1 = models.ForeignKey(A)\n    fieldB2 = models.CharField()\n<\/code><\/pre>\n<p>For having autocomplete in admin interface for model B to the fieldB1, we need<\/p>\n<ol>\n<li>API for model A should be exposed<\/li>\n<\/ol>\n<blockquote>\n<pre><code>#Create a file autocomplete_light_registry.py in the base folder of the project \n#By registering the modelA, the \/autocomplete\/AAutocomplete\/?q=aa API will be available \n#API will search on fieldA1 to give the result\nautocomplete_light.register(A,search_fields=['fieldA1',], )\n<\/code><\/pre>\n<\/blockquote>\n<ol>\n<li>Admin interface should know that fieldB1 should use that exposed API<\/li>\n<\/ol>\n<blockquote>\n<pre><code>#admin.py\nclass BAdmin(admin.ModelAdmin):\n   form = autocomplete_light.modelform_factory(B)\nadmin.site.register(B, BAdmin)\n<\/code><\/pre>\n<\/blockquote>\n\n<div style=\"font-size: 0px; height: 0px; line-height: 0px; margin: 0; padding: 0; clear: both;\"><\/div>","protected":false},"excerpt":{"rendered":"<p>I just wanted to enable autocomplete in my admin interface. It took almost 3 hours to understand whats happening and to make it work, because for integrating in admin interface, the docs is not very clear. You need to read &hellip; <a href=\"http:\/\/www.ramandv.com\/blog\/django-autocomplete_light-admin-interface-integration\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"spay_email":"","jetpack_publicize_message":"","jetpack_is_tweetstorm":false},"categories":[8,18],"tags":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v17.0 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<meta name=\"description\" content=\"Missing Guide for Django admin integration with autocomplete_light.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"http:\/\/www.ramandv.com\/blog\/django-autocomplete_light-admin-interface-integration\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Django autocomplete_light and admin interface integration - Articles for Developers\" \/>\n<meta property=\"og:description\" content=\"Missing Guide for Django admin integration with autocomplete_light.\" \/>\n<meta property=\"og:url\" content=\"http:\/\/www.ramandv.com\/blog\/django-autocomplete_light-admin-interface-integration\/\" \/>\n<meta property=\"og:site_name\" content=\"Articles for Developers\" \/>\n<meta property=\"article:published_time\" content=\"2014-06-14T02:41:36+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2014-06-18T06:55:19+00:00\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"ramandv\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"1 minute\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebSite\",\"@id\":\"http:\/\/www.ramandv.com\/blog\/#website\",\"url\":\"http:\/\/www.ramandv.com\/blog\/\",\"name\":\"Articles for Developers\",\"description\":\"\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"http:\/\/www.ramandv.com\/blog\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"http:\/\/www.ramandv.com\/blog\/django-autocomplete_light-admin-interface-integration\/#webpage\",\"url\":\"http:\/\/www.ramandv.com\/blog\/django-autocomplete_light-admin-interface-integration\/\",\"name\":\"Django autocomplete_light and admin interface integration - Articles for Developers\",\"isPartOf\":{\"@id\":\"http:\/\/www.ramandv.com\/blog\/#website\"},\"datePublished\":\"2014-06-14T02:41:36+00:00\",\"dateModified\":\"2014-06-18T06:55:19+00:00\",\"author\":{\"@id\":\"http:\/\/www.ramandv.com\/blog\/#\/schema\/person\/ca1ede7143462f244081566e6ff97658\"},\"description\":\"Missing Guide for Django admin integration with autocomplete_light.\",\"breadcrumb\":{\"@id\":\"http:\/\/www.ramandv.com\/blog\/django-autocomplete_light-admin-interface-integration\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"http:\/\/www.ramandv.com\/blog\/django-autocomplete_light-admin-interface-integration\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"http:\/\/www.ramandv.com\/blog\/django-autocomplete_light-admin-interface-integration\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Django autocomplete_light and admin interface integration\"}]},{\"@type\":\"Person\",\"@id\":\"http:\/\/www.ramandv.com\/blog\/#\/schema\/person\/ca1ede7143462f244081566e6ff97658\",\"name\":\"ramandv\",\"url\":\"http:\/\/www.ramandv.com\/blog\/author\/ramandv\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"description":"Missing Guide for Django admin integration with autocomplete_light.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"http:\/\/www.ramandv.com\/blog\/django-autocomplete_light-admin-interface-integration\/","og_locale":"en_US","og_type":"article","og_title":"Django autocomplete_light and admin interface integration - Articles for Developers","og_description":"Missing Guide for Django admin integration with autocomplete_light.","og_url":"http:\/\/www.ramandv.com\/blog\/django-autocomplete_light-admin-interface-integration\/","og_site_name":"Articles for Developers","article_published_time":"2014-06-14T02:41:36+00:00","article_modified_time":"2014-06-18T06:55:19+00:00","twitter_misc":{"Written by":"ramandv","Est. reading time":"1 minute"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebSite","@id":"http:\/\/www.ramandv.com\/blog\/#website","url":"http:\/\/www.ramandv.com\/blog\/","name":"Articles for Developers","description":"","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"http:\/\/www.ramandv.com\/blog\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"en-US"},{"@type":"WebPage","@id":"http:\/\/www.ramandv.com\/blog\/django-autocomplete_light-admin-interface-integration\/#webpage","url":"http:\/\/www.ramandv.com\/blog\/django-autocomplete_light-admin-interface-integration\/","name":"Django autocomplete_light and admin interface integration - Articles for Developers","isPartOf":{"@id":"http:\/\/www.ramandv.com\/blog\/#website"},"datePublished":"2014-06-14T02:41:36+00:00","dateModified":"2014-06-18T06:55:19+00:00","author":{"@id":"http:\/\/www.ramandv.com\/blog\/#\/schema\/person\/ca1ede7143462f244081566e6ff97658"},"description":"Missing Guide for Django admin integration with autocomplete_light.","breadcrumb":{"@id":"http:\/\/www.ramandv.com\/blog\/django-autocomplete_light-admin-interface-integration\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["http:\/\/www.ramandv.com\/blog\/django-autocomplete_light-admin-interface-integration\/"]}]},{"@type":"BreadcrumbList","@id":"http:\/\/www.ramandv.com\/blog\/django-autocomplete_light-admin-interface-integration\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Django autocomplete_light and admin interface integration"}]},{"@type":"Person","@id":"http:\/\/www.ramandv.com\/blog\/#\/schema\/person\/ca1ede7143462f244081566e6ff97658","name":"ramandv","url":"http:\/\/www.ramandv.com\/blog\/author\/ramandv\/"}]}},"jetpack_featured_media_url":"","jetpack_publicize_connections":[],"jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p6YZCe-4z","_links":{"self":[{"href":"http:\/\/www.ramandv.com\/blog\/wp-json\/wp\/v2\/posts\/283"}],"collection":[{"href":"http:\/\/www.ramandv.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.ramandv.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.ramandv.com\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"http:\/\/www.ramandv.com\/blog\/wp-json\/wp\/v2\/comments?post=283"}],"version-history":[{"count":5,"href":"http:\/\/www.ramandv.com\/blog\/wp-json\/wp\/v2\/posts\/283\/revisions"}],"predecessor-version":[{"id":288,"href":"http:\/\/www.ramandv.com\/blog\/wp-json\/wp\/v2\/posts\/283\/revisions\/288"}],"wp:attachment":[{"href":"http:\/\/www.ramandv.com\/blog\/wp-json\/wp\/v2\/media?parent=283"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.ramandv.com\/blog\/wp-json\/wp\/v2\/categories?post=283"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.ramandv.com\/blog\/wp-json\/wp\/v2\/tags?post=283"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}