I need to provide a list of objects, that if clicked on, bring you to the object detail page in Django Admin. The URL link needs to have the id, and the actual clickable is the name of the product.
Originally, I hardcoded the URL path as such, but was able to get the ID and Name in the link:
return "<a href='/admin/content/product/%s'>%s</a>" % (str(obj.id), obj.product_name)
Displays in CMS: MyProductName as a clickable link, which will go to product ID x.
Since hardcoding URLs will break the app in production, I am trying to use reverse. I'm trying to replicate the above:
return reverse("admin:content_product_change", args=[str(obj.id), obj.product_name])
But get error:
NoReverseMatch: Reverse for 'content_product_change' with arguments '('1', u'ProductName')' and keyword arguments '{}' not found. 1 pattern(s) tried: [u'admin/content/product/(.+)/$']
reversefunction won't return the whole<a href=""></a>tag, it will only return paths. You should be using it likereturn "<a href='%s'>%s</a>" % (reverse("admin:content_product_change", args=[str(obj.id)]), obj.product_name)