django-model-stats

Display how often models and model fields are used in the database
git clone https://git.ce9e.org/django-model-stats.git

commit
a28cee95fa9ff3d93ae3107784f9e93234d847df
parent
a5fc4466f274f6dbc49c2f0f05bd8fb7481a37ce
Author
Tobias Bengfort <bengfort@mpib-berlin.mpg.de>
Date
2021-11-03 11:29
display stats in template

Diffstat

M model_stats/templates/model_stats/stats.html 25 +++++++++++++++++++++++++
M model_stats/views.py 2 +-

2 files changed, 26 insertions, 1 deletions


diff --git a/model_stats/templates/model_stats/stats.html b/model_stats/templates/model_stats/stats.html

@@ -12,4 +12,29 @@
   12    12 {% endblock %}
   13    13 
   14    14 {% block content %}
   -1    15     <table>
   -1    16         <thead>
   -1    17             <th>{% translate 'Model' %}</th>
   -1    18             <th>{% translate 'Field' %}</th>
   -1    19             <th>{% translate 'Count' %}</th>
   -1    20             <th>{% translate 'Usage' %}</th>
   -1    21         </thead>
   -1    22         <tbody>
   -1    23             {% for model in stats %}
   -1    24                 <tr>
   -1    25                     <th>{{ model.name }}</th>
   -1    26                     <th></th>
   -1    27                     <td>{{ model.count }}</th>
   -1    28                 </tr>
   -1    29                 {% for field in model.fields %}
   -1    30                     <tr>
   -1    31                         <th>{{ model.name }}</th>
   -1    32                         <th>{{ field.name }}</th>
   -1    33                         <td>{{ field.count }}</th>
   -1    34                         <td>{{ field.percent|default:'—' }}</th>
   -1    35                     </tr>
   -1    36                 {% endfor %}
   -1    37             {% endfor %}
   -1    38         </tbody>
   -1    39     </table>
   15    40 {% endblock %}

diff --git a/model_stats/views.py b/model_stats/views.py

@@ -42,5 +42,5 @@ def get_stats():
   42    42 
   43    43 
   44    44 def stats_view(request):
   45    -1     context = {}
   -1    45     context = {'stats': get_stats()}
   46    46     return TemplateResponse(request, 'model_stats/stats.html', context)