Skip to content

Commit

Permalink
Adding the title field to templates and views to reflect the changes …
Browse files Browse the repository at this point in the history
…on the model
  • Loading branch information
sebastian-code committed Mar 17, 2016
1 parent 3c12bb0 commit e727cd9
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 14 deletions.
2 changes: 1 addition & 1 deletion qa/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class Question(models.Model):
closed = models.BooleanField(default=False)

def __str__(self):
return self.question_text
return self.title


class Answer(models.Model):
Expand Down
2 changes: 1 addition & 1 deletion qa/templates/qa/add.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

<form id="add_q" method="post" action="/add/">
{% csrf_token %}
<input class="input-lg" style="width:100%" placeholder="Enter your question....." type="text" name="question"/> <br/><br/>
<input class="input-lg" style="width:100%" placeholder="Enter your question....." type="text" name="title"/> <br/><br/>
<textarea id="ans" rows="7" style="width:100%" placeholder="Explain your question....." type="text" name="description"></textarea>
{% markdown_editor "#ans" %}
{% markdown_media %}
Expand Down
2 changes: 1 addition & 1 deletion qa/templates/qa/answer.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
{% if message %}
<strong>Enter a valid Answer!</strong>
{% endif %}
<h4>Answering Question : {{ question.question_text }}</h4>
<h4>Answering Question : {{ question.title }}</h4>

{% if user.is_authenticated %}
<form id="answer" method="post" action="/answer/">
Expand Down
2 changes: 1 addition & 1 deletion qa/templates/qa/detail.html
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@

<div class="jumbotron">
<small class="pull-right">Posted by {{ question.user_data.user.username }}, {{ question.pub_date }}</small>
<h3><cool>Q: </cool>{{ question.question_text }}</h3>
<h3><cool>Q: </cool>{{ question.title }}</h3>
<h4>{{ question.description }}</h4>
<p>
{% if user.is_authenticated %}
Expand Down
9 changes: 5 additions & 4 deletions qa/templates/qa/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@
<div class="col-sm-1 ans"><small><div class="ques">{{ question.answer_set.count }}</div>Answers</small></div>
<div class="col-sm-1 ans"><small><div class="ques">{{ question.views }}</div>Views</small></div>
<p>
{% if question.reward %}<span class="glyphicon glyphicon-fire" aria-hidden="true"></span>{% endif %} <a class="ques" href="/q/{{ question.id }}/">{{ question.question_text }}</a>
{% if question.reward %}<span class="glyphicon glyphicon-fire" aria-hidden="true"></span>{% endif %}
<h3><a href="{% url 'detail' question.id %}">{{ question.title }}</a></h3>
<br/>
{% for tag in question.tags.all %}
<a href="/tag/{{ tag.slug|slugify }}/"><tag>{{ tag.slug }}</tag></a>
Expand Down Expand Up @@ -72,7 +73,7 @@
<div class="col-sm-1 ans"><small><div class="ques">{{ question.answer_set.count }}</div>Answers</small></div>
<div class="col-sm-1 ans"><small><div class="ques">{{ question.views }}</div>Views</small></div>
<p>
{% if question.answer_set.count %}<span class="glyphicon glyphicon-fire" aria-hidden="true"></span>{% endif %} <a class="ques" href="/q/{{ question.id }}/">{{ question.question_text }}</a>
{% if question.answer_set.count %}<span class="glyphicon glyphicon-fire" aria-hidden="true"></span>{% endif %} <a class="ques" href="/q/{{ question.id }}/">{{ question.title }}</a>
<br/>
{% for tag in question.tags.all %}
<a href="/tag/{{ tag.slug|slugify }}/"><tag>{{ tag.slug }}</tag></a>
Expand All @@ -95,7 +96,7 @@
<div class="col-sm-1 ans"><small><div class="ques">{{ question.answer_set.count }}</div>Answers</small></div>
<div class="col-sm-1 ans"><small><div class="ques">{{ question.views }}</div>Views</small></div>
<p>
{% if question.answer_set.count %}<span class="glyphicon glyphicon-fire" aria-hidden="true"></span>{% endif %} <a class="ques" href="/q/{{ question.id }}/">{{ question.question_text }}</a>
{% if question.answer_set.count %}<span class="glyphicon glyphicon-fire" aria-hidden="true"></span>{% endif %} <a class="ques" href="/q/{{ question.id }}/">{{ question.title }}</a>
<br/>
<reward>Earn <b>{{ question.reward }}</b> points</reward>
{% for tag in question.tags.all %}
Expand Down Expand Up @@ -145,7 +146,7 @@ <h3 class="panel-title">Unanswered Questions</h3>
<div class="panel-body">
<ul>
{% for question in noans %}
<li><a href="/q/{{ question.id }}/">{{ question.question_text }}</a></li>
<li><a href="/q/{{ question.id }}/">{{ question.title }}</a></li>
{% endfor %}
</ul>
</div>
Expand Down
11 changes: 5 additions & 6 deletions qa/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
def search(request):
if request.method == 'POST':
word = request.POST['word']
latest_question_list = Question.objects.filter(question_text__contains=word)
latest_question_list = Question.objects.filter(title__contains=word)
paginator = Paginator(latest_question_list, 10)
page = request.GET.get('page')
try:
Expand Down Expand Up @@ -112,21 +112,19 @@ def add(request):
return HttpResponseRedirect("/login/")

if request.method == 'POST':
question_text = request.POST['question']
question_title = request.POST['title']
question_description = request.POST['description']
tags_text = request.POST['tags']
user_id = request.POST['user']
user = get_user_model().objects.get(id=user_id)

if question_text.strip() == '':
if question_title.strip() == '':
return render(request, 'qa/add.html', {'message': 'Empty'})

question = Question()
question.question_text = question_text
question.title = question_title
question.description = question_description
question.user = user
question.save()

tags = tags_text.split(',')
for tag in tags:
try:
Expand All @@ -138,6 +136,7 @@ def add(request):
tag_object.save()
question.tags.add(tag_object)

question.save()
#send_mail('QA: Your Question has been Posted.', 'Thank you for posting the question, '+question_text+'. We will notify you once someone posts an answer.', '[email protected]', [request.user.email], fail_silently=False)

return HttpResponseRedirect('/')
Expand Down

0 comments on commit e727cd9

Please sign in to comment.