page titles populate drop down on quest page

This commit is contained in:
iou1name 2018-09-05 12:22:45 -04:00
parent 6117fbe1e7
commit eaef094444
3 changed files with 15 additions and 8 deletions

View File

@ -6,7 +6,7 @@ from django.contrib import messages
from django.shortcuts import redirect, render
from .forms import QuestForm, PostForm
from quest.models import Quest, Post
from quest.models import Quest, Post, PageTitle
def index(request):
"""
@ -21,6 +21,12 @@ def index(request):
quest.save()
post.quest = quest
post.save()
page = PageTitle(
quest=quest,
page_num=1,
title="Page 1"
)
page.save()
return redirect('quest:quest', quest_id=quest.id)
else:
quest_form = QuestForm()

View File

@ -19,9 +19,9 @@
{% endif %}
<li>
<select onChange="window.location.href=this.value">
{# for page in pages %}
<option value="{{ url_for('.quest', quest_id=quest_id, page_num=page[1]) }}"{% if page[1] == page_num %} selected="yes"{% endif %}>{{ page[2] }}</option>
{% endfor #}
{% for page in pages %}
<option value="{{ url('quest:quest', args=[quest_id, page.page_num]) }}"{% if page.page_num == page_num %} selected="yes"{% endif %}>{{ page.title }}</option>
{% endfor %}
</select>
</li>
{% endblock %}

View File

@ -5,7 +5,7 @@ Quest and quest accessory views.
from django.shortcuts import render
from django.http import HttpResponse
from .models import Quest, DiceRoll, PollOption, PollVote
from .models import Quest, DiceRoll, PollOption, PollVote, PageTitle
def index(request):
"""
@ -20,11 +20,12 @@ def quest(request, quest_id, page_num=1):
Arbituary quest page view.
"""
quest = Quest.objects.get(id=quest_id)
pages = PageTitle.objects.filter(quest=quest).order_by('page_num')
messages = quest.message_set.all()
posts = quest.post_set.all()
dice_rolls = DiceRoll.objects.filter(dicecall__post__quest__id=quest_id)
poll_options = PollOption.objects.filter(poll__post__quest__id=quest_id)
poll_votes = PollVote.objects.filter(option__poll__post__quest__id=quest_id)
dice_rolls = DiceRoll.objects.filter(dicecall__post__quest=quest)
poll_options = PollOption.objects.filter(poll__post__quest=quest)
poll_votes = PollVote.objects.filter(option__poll__post__quest=quest)
ip_address = request.META['REMOTE_ADDR']
context = locals()
return render(request, 'quest/quest.html', context)