Advertisement
Mochinov

Untitled

Nov 7th, 2021
264
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.94 KB | None | 0 0
  1. def get_queryset(self, request):
  2. # queryset = super(CycleCommonStatAdmin, self).get_queryset(request)
  3. self.cycle_id = request.GET['cycle__id']
  4. self.user_id = request.GET['user__id__exact']
  5. queryset = CycleStatistic.objects.filter(cycle__id=self.cycle_id, user__id=self.user_id)
  6. return queryset
  7.  
  8. def get_events(self, obj):
  9. return "\n".join([event.__str__() for event in obj.cycle.events.all()])
  10.  
  11. def get_events(self, obj):
  12. # each obj will be an Order obj/instance/row
  13. to_return = '''<table class="mytable">
  14. <thead>
  15. <tr>
  16. <td></td>
  17. <td>Трансляция зачтена</td>
  18. <td>Зал зачтен</td>
  19. <td>Архив зачтен</td>
  20. </tr>
  21. </thead>
  22. <tbody>'''
  23. # I'm assuming that there is a name field under the event.Product model. If not change accordingly.
  24. for event in obj.cycle.events.all().order_by('date'):
  25. on_stat = OnlineStatistic.objects.filter(user=obj.user, event=event)
  26. off_stat = OfflineStatistic.objects.filter(user=obj.user, event=event)
  27. arch_stat = ArchiveStatistic.objects.filter(user=obj.user, archive__event=event)
  28. if on_stat:
  29. on_stat = on_stat.get()
  30. on_success = on_stat.get_is_success()
  31. on_link = f'/admin/stats/onlinestatistic/{on_stat.id}/change/'
  32. else:
  33. on_success = "Нет"
  34. on_link = ""
  35. if off_stat:
  36. off_stat = off_stat.get()
  37. off_success = off_stat.get_is_success()
  38. off_link = f'/admin/stats/offlinestatistic/{off_stat.id}/change/'
  39. else:
  40. off_success = "Нет"
  41. off_link = ""
  42. if arch_stat:
  43. arch_stat = arch_stat.get()
  44. arch_success = arch_stat.get_is_success()
  45. arch_link = f'/admin/stats/archivestatistic/{arch_stat.id}/change/'
  46. else:
  47. arch_success = "Нет"
  48. arch_link = ""
  49. to_return += f'''
  50. <tr class="grp-row grp-row-odd" style="border-bottom: 1px solid #eeeeee;">
  51. <td>{event.__str__()}</td>'''
  52. if on_link:
  53. to_return += f'<td><a href="{on_link}" target="_blank">{on_success}</a></td>'
  54. else:
  55. to_return += f'<td>{on_success}</td>'
  56. if off_link:
  57. to_return += f'<td><a href="{off_link}" target="_blank">{off_success}</a></td>'
  58. else:
  59. to_return += f'<td>{off_success}</td>'
  60. if arch_link:
  61. to_return += f'<td><a href="{arch_link}" target="_blank">{arch_success}</a></td>'
  62. else:
  63. to_return += f'<td>{arch_success}</td>'
  64. to_return += '</tr></tbody></table>'
  65. return mark_safe(to_return)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement