Advertisement
Guest User

Untitled

a guest
Mar 27th, 2017
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.88 KB | None | 0 0
  1. poll_qs = Poll.objects.filter(
  2.         event=event
  3.     ).prefetch_related(
  4.         'polloption_set',
  5.         Prefetch(
  6.             'pollanswer_set',
  7.             queryset=PollAnswer.objects.filter(singer=singer_choir_profile).select_related('option').first(),
  8.             to_attr='answer'
  9.         )
  10.     )
  11.  
  12.     for poll in poll_qs:
  13.         if poll.answer:
  14.             poll_answer_form = PollAnswerForm(
  15.                 poll,
  16.                 singer_choir_profile,
  17.                 poll.polloption_set.all(),
  18.                 data or None,
  19.                 initial={'option_%s' % poll.id: poll.answer[0].option.id}
  20.             )
  21.         else:
  22.             poll_answer_form = PollAnswerForm(
  23.                 poll,
  24.                 singer_choir_profile,
  25.                 poll.polloption_set.all(),
  26.                 data or None
  27.             )
  28.         poll_forms.append(poll_answer_form)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement