Skip to content

Commit

Permalink
9 - Question Queryset
Browse files Browse the repository at this point in the history
  • Loading branch information
jmitchel3 committed Jul 13, 2015
1 parent 3386ffc commit 7212fed
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 14 deletions.
Binary file modified src/db.sqlite3
Binary file not shown.
19 changes: 5 additions & 14 deletions src/newsletter/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
from django.core.mail import send_mail
from django.shortcuts import render

from questions.models import Question

from .forms import ContactForm, SignUpForm
from .models import SignUp

Expand All @@ -14,34 +16,23 @@ def home(request):
"form": form
}
if form.is_valid():
#form.save()
#print request.POST['email'] #not recommended
instance = form.save(commit=False)

full_name = form.cleaned_data.get("full_name")
if not full_name:
full_name = "New full name"
instance.full_name = full_name
# if not instance.full_name:
# instance.full_name = "Justin"
instance.save()
context = {
"title": "Thank you"
}

if request.user.is_authenticated() and request.user.is_staff:
#print(SignUp.objects.all())
# i = 1
# for instance in SignUp.objects.all():
# print(i)
# print(instance.full_name)
# i += 1

queryset = SignUp.objects.all().order_by('-timestamp') #.filter(full_name__iexact="Justin")
#print(SignUp.objects.all().order_by('-timestamp').filter(full_name__iexact="Justin").count())
if request.user.is_authenticated():
queryset = Question.objects.all().order_by('-timestamp')
context = {
"queryset": queryset
}
return render(request, "questions/home.html", context)

return render(request, "home.html", context)

Expand Down
Binary file modified src/newsletter/views.pyc
Binary file not shown.
22 changes: 22 additions & 0 deletions src/templates/questions/home.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{% extends "base.html" %}



{% block content %}



{% for question in queryset %}

<li>{{ question.text }}
<ul>
{% for ans in question.answer_set.all %}
<li>{{ ans.text }}</li>
{% endfor %}
</ul>
</li>

{% endfor %}


{% endblock %}

0 comments on commit 7212fed

Please sign in to comment.