Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #TABLE DOWNLOAD
- ____________________________________________
- | email | PUB (FK_DOCUMENT) |
- | __________________________________________ |
- |test12@gmail.com | 1 |
- | __________________________________________ |
- |test12@gmail.com | 2 |
- | __________________________________________ |
- |test45@gmail.com | 4 |
- | __________________________________________ |
- |test22@gmail.com | 3 |
- | __________________________________________ |
- |test01@gmail.com | 2 |
- | __________________________________________ |
- |test98@gmail.com | 4 |
- | __________________________________________ |
- |test74@gmail.com | 4 |
- | __________________________________________ |
- #TABLE DOCUMENT
- __________________
- | ID | EDQM_ID |
- | ________________ |
- |1 | A |
- | ________________ |
- |2 | B |
- | ________________ |
- |3 | C |
- | ________________ |
- |4 | D |
- | ________________ |
- #HTML STATISTICS TABLE
- ________________________
- | PUB_ID | Requests |
- | _____________________ |
- |A | 1 |
- | _____________________ |
- |B | 2 |
- | _____________________ |
- |C | 1 |
- | _____________________ |
- |D | 3 |
- | _____________________ |
- pub_id = Download.objects.values_list('pub__edqm_id').distinct()
- <QuerySet [('A',), ('B',), ('C',), ('D',)]>
- requests = Download.objects.values_list('pub__edqm_id').annotate(count=Count('pub__edqm_id'))
- <QuerySet [('TEST-02', 12), ('FORMSET-3', 1), ('EPUB TEST', 3), ('TEST-01', 9), ('FORMSET 03', 13), ('FORMSET 3 bi', 24), ('BIO 01', 87)]>
- <table id="DocumentTable" class="table table-bordered table-striped table-condensed table_model">
- <thead>
- <caption style="border: inherit; background-color: lightgrey;">
- <span><strong>Download per Publication</strong></span>
- </caption>
- <tr>
- <th>{% trans 'Publications' %}</th>
- <th>{% trans 'Requests' %}</th>
- <th>{% trans 'Max download number' %}</th>
- <th>{% trans 'Average download number' %}</th>
- </tr>
- </thead>
- <tbody>
- <tr>
- <td>PUB_ID here </td>
- <td><span class="badge alert-danger"> Requests here </span></td>
- <td> </td>
- <td> </td>
- </tr>
- </tbody>
- </table>
- class StatsView(View):
- template_name = 'freepub/stats.html'
- def get(self, request):
- subtitle = _("Statistics")
- #Some values display in my template
- customers_count = Customer.objects.all().count()
- publications_count = Publication.objects.all().count()
- downloads_count = Download.objects.all().count()
- last_download_temp = Download.objects.latest('id').download_date
- last_download = last_download_temp.strftime('%Y-%m-%d %H:%M:%S ')
- document = Document.objects.all()
- #Populate HTML table
- pub_id = Download.objects.values_list('pub__edqm_id').distinct()
- fieldname = Download.objects.values_list('pub__edqm_id').annotate(count=Count('pub__edqm_id'))
- context = {'subtitle': subtitle,
- 'fieldname': fieldname,
- 'customers_count': customers_count,
- 'publications_count': publications_count,
- 'downloads_count': downloads_count,
- 'last_download': last_download,
- 'document': document}
- return render(request, self.template_name, context)
Add Comment
Please, Sign In to add comment