add is_free annotations on subject lists
parent
be0ab46872
commit
cdfe5d99d6
|
@ -8,17 +8,23 @@
|
|||
<p>
|
||||
Below is a list of subjects for books that users have added to
|
||||
wishlists. It is here primarily to show what subjects are present
|
||||
in the database to guide further development. You can order by the
|
||||
<a href="{% url subjects %}">subject name</a> or by the
|
||||
<a href="{% url subjects %}?order=count">number</a> of works
|
||||
with that subject.
|
||||
in the database to guide further development.
|
||||
</p>
|
||||
<ul>
|
||||
<li> ordered by <a href="{% url subjects %}">subject name</a> </li>
|
||||
<li> ordered by <a href="{% url subjects %}?order=count">number</a> of works with the subject.</li>
|
||||
<li> ordered by <a href="{% url subjects %}?subset=free">subject name</a> (free works only)</li>
|
||||
<li> ordered by <a href="{% url subjects %}?order=count&subset=free">number</a> of free works with the subject.</li>
|
||||
</ul>
|
||||
|
||||
<p>
|
||||
<ul>
|
||||
{% for subject in subjects %}
|
||||
|
||||
<li><a href="{% url free %}kw.{{ subject.name }}/">{{ subject.name }}</a> ({{ subject.works__count }}). {% if request.user.is_staff %} <a href="{% url free %}?setkw={{ subject.name }}">set keywords</a>{% endif %}</li>
|
||||
<li><a href="{% url free %}kw.{{ subject.name }}/">{{ subject.name }}</a>
|
||||
({% if subject.works__is_free__count %}{{ subject.works__is_free__count }} free out of {{ subject.works.all.count }}{% else %}{{ subject.works__count }}{% endif %} total works).
|
||||
{% if request.user.is_staff %} <a href="{% url free %}?setkw={{ subject.name }}">set keywords</a>{% endif %}
|
||||
</li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
</p>
|
||||
|
|
|
@ -768,12 +768,19 @@ def googlebooks(request, googlebooks_id):
|
|||
def subjects(request):
|
||||
order = request.GET.get('order')
|
||||
subjects = models.Subject.objects.all()
|
||||
subjects = subjects.annotate(Count('works'))
|
||||
|
||||
if request.GET.get('order') == 'count':
|
||||
subjects = subjects.order_by('-works__count')
|
||||
subjects = subjects
|
||||
if request.GET.get('subset') == 'free':
|
||||
subjects = models.Subject.objects.filter(works__is_free = True).annotate(Count('works__is_free'))
|
||||
if request.GET.get('order') == 'count':
|
||||
subjects = subjects.order_by('-works__is_free__count')
|
||||
else:
|
||||
subjects = subjects.order_by('name')
|
||||
else:
|
||||
subjects = subjects.order_by('name')
|
||||
subjects = models.Subject.objects.all().annotate(Count('works'))
|
||||
if request.GET.get('order') == 'count':
|
||||
subjects = subjects.order_by('-works__count')
|
||||
else:
|
||||
subjects = subjects.order_by('name')
|
||||
|
||||
return render(request, 'subjects.html', {'subjects': subjects})
|
||||
|
||||
|
|
Loading…
Reference in New Issue