martsberger / django-pivot

A module for pivoting Django Querysets
MIT License
209 stars 16 forks source link

Possibility to attach queryset to number #2

Open jangeador opened 6 years ago

jangeador commented 6 years ago

Could it be possible to keep a queryset or some sort of way that we could make the pivot number be attached to the records that produced the number to be able to make the number a list that would allow to drill down to the records. I was thinking of maybe adding the data or queryset as an item to each records dict, or whatever other way may be more practical.

Currently I am generating drilldown lists using django-filter and get parameters like this:

def build_url(*args, **kwargs):
    params = kwargs.pop('params', {})
    url = reverse(*args, **kwargs)
    if not params: return url

    qdict = QueryDict('', mutable=True)
    for k, v in params.items():
        if type(v) is list:
            qdict.setlist(k, v)
        else:
            qdict[k] = v

    return url + '?' + qdict.urlencode()

def render_as_links(self, request, record):
        params = {'performance': record['performance'], 'grade': record['grade'],
                  **self.request.GET}
        href = build_url('afb:table_proficiency_model_detail', params=params)
        return format_html(
            '<a href={href}>{text}</a>',
            href=href,
            text=value
        )

But it would be a lot easier if the queryset was already attached to the record. I hope this is not too out of scope.

Thanks in advance.