Browse Source

tried search queries - fial

newsletter
Esther Kleinhenz 6 years ago
parent
commit
3d9e40f840

+ 6
- 3
application/templates/blog_search_list_view.html View File

{% extends "base.html" %} {% block content %} {% extends "base.html" %} {% block content %}

<div id="tag-cloud">
{% load taggit_templatetags2_tags %}
{% get_taglist as tags for 'application.post' %}
<div id="">
<ul> <ul>
{% for tag in tags %} {% for tag in tags %}
<li>{{tag}} ({{tag.num_times}})</li>
<li>{{tag}} ({{tag.num_times}})
</li>
{{ result }}
{% endfor %} {% endfor %}
</ul> </ul>
</div> </div>

+ 9
- 4
application/templates/post_detail.html View File

</div> </div>
{% else %} {% else %}
<a class="btn btn-outline-dark" href="{% url 'post_publish' pk=post.pk %}">Publish</a> <a class="btn btn-outline-dark" href="{% url 'post_publish' pk=post.pk %}">Publish</a>
{% endif %}
{% if user.is_staff and user == post.author %}
{% endif %} {% if user.is_staff and user == post.author %}
<a class="btn btn-outline-dark" href="{% url 'post_edit' pk=post.pk %}"> <a class="btn btn-outline-dark" href="{% url 'post_edit' pk=post.pk %}">
<span class="glyphicon glyphicon-pencil">Edit</span> <span class="glyphicon glyphicon-pencil">Edit</span>
</a> </a>
{% endif %} {% endif %}
<h1>{{ post.title }}</h1> <h1>{{ post.title }}</h1>
<p>{{ post.text|linebreaksbr }}</p> <p>{{ post.text|linebreaksbr }}</p>
<p>{{ post.tag }}</p>

<p>
{% for tag in post.tags.all %}
<a href="{% url 'blog_search_list_view' %}">{{ tag.name }}, </a>
{% endfor %}
</p>
<p>
Autor: {{ post.author }}
</p>
</div> </div>
{% endblock %} {% endblock %}

+ 0
- 9
application/templates/post_list.html View File



</div> </div>
{% endfor %} {% endfor %}
{% include "taggit_templatetags2/tagcanvas_include_js_static.html" %}

<div id="tag-cloud">
<ul>
{% for tag in tags %}
<li>{{tag}} ({{tag.num_times}})</li>
{% endfor %}
</ul>
</div>
</div> </div>
{% endblock %} {% endblock %}

+ 12
- 14
application/views.py View File



@login_required @login_required
def student_page(request): def student_page(request):
return render(request, 'student_page.html', {})

def blog_search_list_view(post_list, self):
result = super(post_list, self).get_queryset()
query = self.request.GET.get('q')
if query:
query_list = query.split()
result = result.filter(
reduce(operator.and_,
(Q(title__icontains=q) for q in query_list)) |
reduce(operator.and_,
(Q(content__icontains=q) for q in query_list))
)
return result
q = request.GET.get('q')
query = Q()
for word in q or []:
query = query | Q(tags__name__icontains=word)
result = Post.objects.filter(query)
return render(request, 'blog_search_list_view.html', {'result':result})


def blog_search_list_view(request):

return render(request, 'blog_search_list_view.html', {})

Loading…
Cancel
Save