I apologise in advance for the length of my post but I have included all the detail I can.
I have the following structure for an app. The list view template uses Bootstrap DataTables. My question is how to amend the urls to return the change url in django-admin.
models.py
def get_absolute_url(self):
return reverse('contact_detail', kwargs={"id":
self.id})
urls.py
from django.conf.urls import url
from .views import (
contacts_list,
contacts_detail,
)
urlpatterns = [
url(r'^$', contacts_list, name='contact_list'),
url(r'^(?P<id>\d+)/$', contacts_detail, name='contact_detail'),
]
views.py
from django.contrib.auth.decorators import user_passes_test
from django.shortcuts import render, get_object_or_404
from .models import Contact
@user_passes_test(lambda u: u.is_staff)
def contacts_list(request):
c = {}
contacts = Contact.objects.all()
c['contacts'] = contacts
return render(request, 'contacts/contacts_list.html', c)
def contacts_detail(request, id=None):
instance = get_object_or_404(Contact, id=id)
context = {
"title": "Contact Details",
"instance": instance,
}
return render(request, "contacts/contacts_detail.html", context)
contact_list.html
<td><a href='{{ contact.get_absolute_url }}'>{{
contact.id }}</a></td>
Any advice would be appreciated.