Guest User

Untitled

a guest
Dec 16th, 2018
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.11 KB | None | 0 0
  1. {% block content %}
  2. <h1 class="center">Search results</h1>
  3. {% if object_list.count == 0 %}
  4. <div class="search_not_found">
  5. <img src={% static "/gfx/sys/not_found.png" %}>
  6. <h2>Nothing found here ...</h2>
  7. </div>
  8. {% else %}
  9. {% for post in object_list %}
  10. <div class="post">
  11. <h3><u><a href="{% url 'post_detail' pk=post.pk %}">{{ post.title }}</a></u></h3>
  12. <p>{{ post.content|safe|slice:":800"|linebreaksbr}}
  13. {% if post.content|length > 300 %}
  14. <a href="{% url 'post_detail' pk=post.pk %}">... more</a>
  15. {% endif %}</p>
  16. <div class="date">
  17. <a>Published by: <a style="font-weight: bold;" href="{% url 'profile' pk=user.pk %}" >{{ post.author }}</a></a><br>
  18. <a>Published at: {{ post.published_date }}</a><br>
  19. <a>Category: {{ post.category }}</a><br>
  20. <a>Tag(s): {{ post.tag }}</a>
  21. </div>
  22. </div>
  23. {% endfor %}
  24. {% endif %}
  25. {% endblock %}
  26.  
  27. def globalsearch_elastic(request):
  28. keywords = request.GET.get('qs')
  29.  
  30. if keywords:
  31. posts = PostDocument.search().query("match", title=keywords)
  32. else:
  33. posts = ''
  34. return render(request, 'myproject/search_results_elastic.html', {'object_list':posts})
  35.  
  36. ...
  37. class Post(models.Model):
  38. author = models.ForeignKey('myproject_Accounts.User', on_delete=models.CASCADE)
  39. title = models.CharField(max_length=42)
  40. content = models.TextField(max_length=5000)
  41. tag = models.CharField(max_length=50, blank=True)
  42. category = models.ForeignKey(Category, verbose_name="Category", on_delete=models.CASCADE, null=True)
  43. postattachment = fields.FileField(blank=True ,null=True, upload_to=get_file_path_user_uploads)
  44. postcover = fields.ImageField(null=True, upload_to=get_file_path_user_uploads, dependencies=[
  45. FileDependency(processor=ImageProcessor(format='JPEG', quality=90, scale={'max_width': 700, 'max_height': 700}))])
  46. created_date = models.DateField(auto_now_add=True)
  47. published_date = models.DateField(blank=True, null=True)
  48. ...
Add Comment
Please, Sign In to add comment