Skip to content

Feature Request: Make dict a option instead of a list in MultiTableMixin #997

@Frodothedwarf

Description

@Frodothedwarf

I've used this project for a good while now, and the SingleTableMixin are working great, but I'm at a place where I need to use multiple tables on one view.

I figured it must be at least as useful, but I've figured it's a lot harder to do so.
By making a dict option instead of a list option only, you can easily reference the tables at the places they go.

In the current flow you need to do it like this:

class DetailView(PermissionRequiredMixin, MultiTableMixin, DetailView):
    permission_required = ["permission"]
    model = Model
    template_name = "template.html"
    tables = [
        ModelTable
    ]

    def get_tables_data(self):
        return [
            self.object
        ]

And then in the template you have to loop through the list like this:

{% for table in tables %}
    {% if table.prefix == "model_table" %}
        {% render_table table %}
    {% endif %}
{% endfor %}

I want to eliminate the need for looping through the tables to find the correct one, and I would hope that a option would be something like:

class DetailView(PermissionRequiredMixin, MultiTableMixin, DetailView):
    permission_required = ["permission"]
    model = Model
    template_name = "template.html"
    tables = {"model_table": ModelTable}

    def get_tables_data(self):
        return {
            "model_table": self.object
        }

With a template that looks like:
{% render_table_dict "model_table" %}

I can make the commits, but first wanted to know if it's something of interest for the project as a whole? I at least would think that alot of people would benefit from a change like this.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions