django-tables2 icon indicating copy to clipboard operation
django-tables2 copied to clipboard

Allowing the first column of SingleTableMixin to use LinkColumn?

Open vincentwhales opened this issue 5 years ago • 5 comments

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 avatar Apr 26 '19 23:04 vincentwhales

@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()?

jieter avatar Apr 27 '19 18:04 jieter

@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

vincentwhales avatar Apr 29 '19 16:04 vincentwhales

We might be able to incorporate such a feature into django-tables2, if someone is willing to implement it ;)

jieter avatar Apr 29 '19 17:04 jieter

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?

vincentwhales avatar May 13 '19 19:05 vincentwhales

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.

jieter avatar May 14 '19 07:05 jieter