Django CMS absolute url for Elasticsearch
<p>i write a command for django app like this :</p>

<pre><code>for p in Article.public.all():
    data += '{"index": {"_id": "%s", "_type": "article"}}\n' % p.pk
    data += json.dumps({
        "title": p.title,
        "category": p.category.category,
        "content_type": p.content_type,
        "duration": p.get_audio_duration(),
        "thumbnail": p.get_thumbnail(),
        "date": datetime.strftime(p.date, '%d.%m.%Y'),
        "url": p.get_absolute_url(),
        "content": p.content
    }) + '\n'

response = requests.put('{}/radio_index/_bulk'.format(settings.ES_URL), data=data)
</code></pre>

<p><code>get_absolute_url</code> method looks like this:</p>

<pre><code>    def get_absolute_url(self):
        return reverse('tv_article_hook:article_tv_detail', kwargs={'slug': self.slug})
</code></pre>

<p>I am using Django CMS apphooks. Apphook urls are:</p>

<pre><code>urlpatterns = patterns('', 
                       url(r'^$', ArticleTvListView.as_view(), name='article_tv_list'),
                       url(r'^(?P&lt;slug&gt;[^/]+)/$', ArticleTvView.as_view(), name='article_tv_detail')
                   )
</code></pre>

<p>When i am using <code>get_absolute_url</code> in template or in REST api it works fine. But when i run command via <code>manage.py feed_index</code> code fails on <code>p.get_absolute_url</code> with error:</p>

<p><code>django.core.urlresolvers.NoReverseMatch: Reverse for 'article_tv_detail' with arguments '()' and keyword arguments '{'slug': 'some slug'}' not found. 0 pattern(s) tried: []</code></p>

<p>How can i solve this problem ? </p>

<p>You will need to ensure that Django itself, not just CMS, knows the app's namespace, <code>tv_article_hook</code>.</p>

<p>I suspect that is registered with CMS, but not a namespace which Django knows about. Now depending on what version of Django you're using there's a couple of ways to define the namespace for Django. But have a read of the <a href="https://docs.djangoproject.com/en/1.10/ref/applications/#for-application-authors" rel="nofollow">application docs</a>, essentially you can define your own app config like so;</p>

<pre><code># tv_article/__init__.py

default_app_config = 'tv_article.apps.TVArticleConfig'

# tv_article/apps.py

from django.apps import AppConfig

class TVArticleConfig(AppConfig):
    name = 'tv_article'
    verbose_name = "TV Article"
</code></pre>

<p>With that setup, you should then be able to modify your code like so (removing '_hook' from your CMS namespace as well because thats a CMS term, but we're just talking about a Django app here);</p>

<pre><code>def get_absolute_url(self):
    return reverse('tv_article:article_tv_detail', kwargs={'slug': self.slug})
</code></pre>

python django elasticsearch django-cms