readonly_fields returns empty value in django inlined models
<p>i am new in django framework, in my current try, i have two models (Client and Facture). Facture is displayed as a TabularInline in client change view.</p>

<p>i want display a link for each inlined facture object to download the file. so i added a custom view that download the facture file, but dont know how to link to it</p>

<pre><code>class Client(models.Model):
    ...

class Facture(models.Model):
    client = models.ForeignKey(Client, on_delete=models.CASCADE)
    numero = models.IntegerField(unique=True, default=rand_code)
    ...
</code></pre>

<p>and in the admin.py:</p>

<pre><code>class FactureInline(admin.TabularInline):

    model = Facture
    extra = 0

    readonly_fields = ('numero', 'dl_link')

    def DLFacture(self, request, obj):
        ...
        response.write(pdf)
        return response

    def get_urls(self):
        urls = super(FactureAdmin, self).get_urls()
        from django.conf.urls import url
        download_url = [
            url(r'^(?P&lt;pk&gt;\d+)/download/$', self.admin_site.admin_view(self.DLFacture), name="download"),
        ]
        return download_url + urls

    def dl_link(self, obj):
        from django.core.urlresolvers import reverse
        return reverse("admin:clients_facture_download", args=[obj.pk])

admin.site.register(Facture, FactureAdmin)

class ClientAdmin(admin.ModelAdmin):
    inlines = [
        FactureInline,
    ]
admin.site.register(Client, ClientAdmin)
</code></pre>

<p>i get the following error:</p>

<pre><code>Reverse for 'clients_facture_download' with arguments '(1,)' and keyword arguments '{}' not found. 0 pattern(s) tried: []
</code></pre>

<p>all works fine when i change the reverse url to</p>

<pre><code>reverse("admin:clients_facture_change", args=[obj.pk])
</code></pre>

<p>so any one could help me know how to reverse the download view and if i am doing thinks right ?</p>

<p>thanks for any help</p>

<p>I would think you need to reverse the order in the url:</p>

<pre><code>url(r'^download/(?P&lt;pk&gt;\d+)$', self.admin_site.admin_view(self.DLFacture), name="download"),
    ]
</code></pre>

python django django-admin django-views django-urls