django-tables2
django-tables2 copied to clipboard
Allowing the first column of SingleTableMixin to use LinkColumn?
Right now I am using a view like this:
class GenericListView(LoginRequiredMixin, SingleTableMixin, ListView):
template_name = 'generic/list.html'
context_table_name = 'object_list'
ordering = ['-id']
How can I tell SingleTableMixin to have the first column (typically id) to use something like this?
tables.LinkColumn(viewname='myapp:mymodel-detail', args=[A('pk')])
@vincentwhales There is currently no way to have the default table created add links. I suspect you want something like the admin default letting the first column link to the records get_absolute_url()
?
@vincentwhales There is currently no way to have the default table created add links. I suspect you want something like the admin default letting the first column link to the records
get_absolute_url()
?
Yes that is what I want.
What would you recommend me to do to in this case? Most of my apps are using django_tables so I just want to make it easy to integrate this functionality across all my tables
We might be able to incorporate such a feature into django-tables2, if someone is willing to implement it ;)
Hey @jieter
I have been looking at the issue and I am stuck on where this code should actually exist.
So far, my guess is that I should override column_for_field
I think another approach will be for me to create my own LinkColumn that is injected as the first column into Library during runtime. This is more like a personalized approach to my app, not something that should be a PR.
Do you have any suggestions?
If we want it to be a an option for generated tables, I'd say table_factory
is the place to add this.
In turn, it needs a linkify
Meta attribute allowing something like this:
class PersonTable(tables.Table):
class Meta:
linkify = ('id', )
table_factory needs to pass on this option just like the other options it takes.