representative_detail_positions.py 973 Bytes
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# coding: utf-8

from django.db import models

from representatives_positions.models import Position

from .representative_detail_base import RepresentativeDetailBase


class RepresentativeDetailPositions(RepresentativeDetailBase):
    template_name = 'representatives/representative_detail_positions.html'

    def get_queryset(self):
        qs = super(RepresentativeDetailPositions, self).get_queryset()

        qs = qs.prefetch_related(
            models.Prefetch(
                'positions',
                queryset=Position.objects.filter(published=True)
                .order_by('-datetime', 'pk')
21
            ),
22
            'positions__themes',
23
            'positions__position_score'
24
25
26
27
28
29
30
31
32
33
34
35
        )

        return qs

    def get_context_data(self, **kwargs):
        c = super(RepresentativeDetailPositions,
                  self).get_context_data(**kwargs)

        c['tab'] = 'positions'
        c['positions'] = c['object'].positions.all()

        return c