optimizing database requests
This commit is contained in:
parent
b39f529af2
commit
2a4c5b1f22
|
@ -63,6 +63,17 @@ class Conference(models.Model):
|
||||||
return str(self.site)
|
return str(self.site)
|
||||||
|
|
||||||
|
|
||||||
|
class ParticipantManager(models.Manager):
|
||||||
|
def get_queryset(self):
|
||||||
|
qs = super().get_queryset()
|
||||||
|
qs = qs.annotate(
|
||||||
|
accepted_talk_count=models.Sum(models.Case(models.When(talk__accepted=True, then=1), default=0, output_field=models.IntegerField())),
|
||||||
|
pending_talk_count=models.Sum(models.Case(models.When(talk__accepted=None, then=1), default=0, output_field=models.IntegerField())),
|
||||||
|
refused_talk_count=models.Sum(models.Case(models.When(talk__accepted=False, then=1), default=0, output_field=models.IntegerField())),
|
||||||
|
)
|
||||||
|
return qs
|
||||||
|
|
||||||
|
|
||||||
class Participant(PonyConfModel):
|
class Participant(PonyConfModel):
|
||||||
|
|
||||||
site = models.ForeignKey(Site, on_delete=models.CASCADE)
|
site = models.ForeignKey(Site, on_delete=models.CASCADE)
|
||||||
|
@ -90,6 +101,8 @@ class Participant(PonyConfModel):
|
||||||
|
|
||||||
conversation = models.OneToOneField(MessageThread)
|
conversation = models.OneToOneField(MessageThread)
|
||||||
|
|
||||||
|
objects = ParticipantManager()
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
# A User can participe only once to a Conference (= Site)
|
# A User can participe only once to a Conference (= Site)
|
||||||
unique_together = ('site', 'email')
|
unique_together = ('site', 'email')
|
||||||
|
|
|
@ -65,11 +65,11 @@
|
||||||
<tr>
|
<tr>
|
||||||
<td><a href="{% url 'participant-details' participant.token %}">{{ participant }}</a></td>
|
<td><a href="{% url 'participant-details' participant.token %}">{{ participant }}</a></td>
|
||||||
<td>
|
<td>
|
||||||
<span class="text-success">{% blocktrans count accepted=participant.accepted_talk_set.count %}accepted: {{ accepted }}{% plural %}accepted: {{ accepted }}{% endblocktrans %}</span>
|
<span class="text-success">{% blocktrans count accepted=participant.accepted_talk_count %}accepted: {{ accepted }}{% plural %}accepted: {{ accepted }}{% endblocktrans %}</span>
|
||||||
—
|
—
|
||||||
<span class="text-warning">{% blocktrans count pending=participant.pending_talk_set.count %}pending: {{ pending }}{% plural %}pending: {{ pending }}{% endblocktrans %}</span>
|
<span class="text-warning">{% blocktrans count pending=participant.pending_talk_count %}pending: {{ pending }}{% plural %}pending: {{ pending }}{% endblocktrans %}</span>
|
||||||
—
|
—
|
||||||
<span class="text-danger">{% blocktrans count refused=participant.refused_talk_set.count %}refused: {{ refused }}{% plural %}refused: {{ refused }}{% endblocktrans %}</span>
|
<span class="text-danger">{% blocktrans count refused=participant.refused_talk_count %}refused: {{ refused }}{% plural %}refused: {{ refused }}{% endblocktrans %}</span>
|
||||||
</td>
|
</td>
|
||||||
{% comment %}
|
{% comment %}
|
||||||
<td>
|
<td>
|
||||||
|
|
|
@ -195,7 +195,7 @@ def talk_list(request, conference):
|
||||||
glyphicon = 'sort'
|
glyphicon = 'sort'
|
||||||
sort_urls[c] = url.urlencode()
|
sort_urls[c] = url.urlencode()
|
||||||
sort_glyphicons[c] = glyphicon
|
sort_glyphicons[c] = glyphicon
|
||||||
talks = talks.prefetch_related('speakers')
|
talks = talks.prefetch_related('category', 'speakers')
|
||||||
return render(request, 'cfp/staff/talk_list.html', {
|
return render(request, 'cfp/staff/talk_list.html', {
|
||||||
'show_filters': show_filters,
|
'show_filters': show_filters,
|
||||||
'talk_list': talks,
|
'talk_list': talks,
|
||||||
|
|
Loading…
Reference in New Issue
Block a user