code: def to_pivot_table(self, fieldnames=(), verbose=True,
                         values=None, rows=None, cols=None,
                         aggfunc='mean', fill_value=None, margins=False,
                         dropna=True, coerce_float=True):
          
          df = self.to_dataframe(fieldnames, verbose=verbose,
                                 coerce_float=coerce_float)
  
          return df.pivot_table(values=values, fill_value=fill_value, index=rows,
                                columns=cols, aggfunc=aggfunc, margins=margins,
                                dropna=dropna)
docs: A convenience method for creating a spread sheet style pivot table
          as a DataFrame
          Parameters
          ----------
          fieldnames:  The model field names(columns) to utilise in creating
                       the DataFrame. You can span a relationships in the usual
                       Django ORM way by using the foreign key field name
                       separated by double underscores and refer to a field
                       in a related model.
  
          values:  The field to use to calculate the values to aggregate.
  
          rows:  The list of field names to group on
                 Keys to group on the x-axis of the pivot table
  
          cols:  The list of column names or arrays to group on
                 Keys to group on the y-axis of the pivot table
  
          aggfunc:  How to arregate the values. By default this would be
                    ``numpy.mean``. A list of aggregates functions can be passed
                    In this case the resulting pivot table will have
                    hierarchical columns whose top level are the function names
                    (inferred from the function objects themselves)
  
          fill_value:  A scalar value to replace the missing values with
  
          margins:  Boolean, default False Add all row / columns
                    (e.g. for subtotal / grand totals)
  
          dropna:  Boolean, default True.
                   Do not include columns whose entries are all NaN
  
          verbose: If this is ``True`` then populate the DataFrame with the
                   human readable versions for foreign key fields else use the
                   actual values set in the model
  
          coerce_float:   Attempt to convert values to non-string, non-numeric
                          objects (like decimal.Decimal) to floating point.