Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def get_queryset(self, request):
- # queryset = super(CycleCommonStatAdmin, self).get_queryset(request)
- self.cycle_id = request.GET['cycle__id']
- self.user_id = request.GET['user__id__exact']
- queryset = CycleStatistic.objects.filter(cycle__id=self.cycle_id, user__id=self.user_id)
- return queryset
- def get_events(self, obj):
- return "\n".join([event.__str__() for event in obj.cycle.events.all()])
- def get_events(self, obj):
- # each obj will be an Order obj/instance/row
- to_return = '''<table class="mytable">
- <thead>
- <tr>
- <td></td>
- <td>Трансляция зачтена</td>
- <td>Зал зачтен</td>
- <td>Архив зачтен</td>
- </tr>
- </thead>
- <tbody>'''
- # I'm assuming that there is a name field under the event.Product model. If not change accordingly.
- for event in obj.cycle.events.all().order_by('date'):
- on_stat = OnlineStatistic.objects.filter(user=obj.user, event=event)
- off_stat = OfflineStatistic.objects.filter(user=obj.user, event=event)
- arch_stat = ArchiveStatistic.objects.filter(user=obj.user, archive__event=event)
- if on_stat:
- on_stat = on_stat.get()
- on_success = on_stat.get_is_success()
- on_link = f'/admin/stats/onlinestatistic/{on_stat.id}/change/'
- else:
- on_success = "Нет"
- on_link = ""
- if off_stat:
- off_stat = off_stat.get()
- off_success = off_stat.get_is_success()
- off_link = f'/admin/stats/offlinestatistic/{off_stat.id}/change/'
- else:
- off_success = "Нет"
- off_link = ""
- if arch_stat:
- arch_stat = arch_stat.get()
- arch_success = arch_stat.get_is_success()
- arch_link = f'/admin/stats/archivestatistic/{arch_stat.id}/change/'
- else:
- arch_success = "Нет"
- arch_link = ""
- to_return += f'''
- <tr class="grp-row grp-row-odd" style="border-bottom: 1px solid #eeeeee;">
- <td>{event.__str__()}</td>'''
- if on_link:
- to_return += f'<td><a href="{on_link}" target="_blank">{on_success}</a></td>'
- else:
- to_return += f'<td>{on_success}</td>'
- if off_link:
- to_return += f'<td><a href="{off_link}" target="_blank">{off_success}</a></td>'
- else:
- to_return += f'<td>{off_success}</td>'
- if arch_link:
- to_return += f'<td><a href="{arch_link}" target="_blank">{arch_success}</a></td>'
- else:
- to_return += f'<td>{arch_success}</td>'
- to_return += '</tr></tbody></table>'
- return mark_safe(to_return)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement