I want to add a link to my listview using linkify in the Columns of the API Reference. I am using Django 2 with Django_tables2 v 2.0.0b3
I have a URL with two context variables name
, which is passed from the ListView and the slug field species
:
URL.py
app_name = 'main'
urlpatterns = [
#The list view
path('genus/<slug:name>/species/', views.SpeciesListView.as_view(), name='species_list'),
# The Detail view
path('genus/<name>/species/<slug:species>', views.SpeciesDetailView.as_view(), name='species'),
]
The DetailView is currently accessible if I manually type the URL.
I want to use the option where I can enter a tuple with (viewname, args/kwargs).
For the tables.py I tried:
class SpeciesTable(tables.Table):
species =tables.Column(linkify=('main:species', {'name': name,'slug':species}))
This gave a NameError: name 'species' is not defined
.
species =tables.Column(linkify=('main:species', {'name': kwargs['name'],'slug':kwargs['species']}))
This gave a NameError: name 'kwargs' is not defined
.
I also tried changing the following variables to strings:
species =tables.Column(linkify=('main:species', {'name': 'name','slug':'species'}))
species =tables.Column(linkify=('main:species', {'name': 'name','slug':'object.species'}))
These attempts gave a NoReverseMatch Reverse for 'species' with keyword arguments '{'name': 'name', 'slug': 'species'}' not found. 1 pattern(s) tried: ['genus\\/(?P<name>[^/]+)\\/species\\/(?P<species>[-a-zA-Z0-9_]+)$']
Formatting it as any of the following will give a SyntaxError
:
species =tables.Column(kwargs={'main:species','name': name,'slug':species})
species =tables.Column(args={'main:species','name': name,'slug':species})
species =tables.Column(kwargs:{'main:species','name': name,'slug':species})
species =tables.Column(args:{'main:species','name': name,'slug':species})
How would I add a link similar to {% url "main:species" name=name species =object.species %}
? Currently there are no example in the docs to do this.