Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- {% block content %}
- <h1 class="center">Search results</h1>
- {% if object_list.count == 0 %}
- <div class="search_not_found">
- <img src={% static "/gfx/sys/not_found.png" %}>
- <h2>Nothing found here ...</h2>
- </div>
- {% else %}
- {% for post in object_list %}
- <div class="post">
- <h3><u><a href="{% url 'post_detail' pk=post.pk %}">{{ post.title }}</a></u></h3>
- <p>{{ post.content|safe|slice:":800"|linebreaksbr}}
- {% if post.content|length > 300 %}
- <a href="{% url 'post_detail' pk=post.pk %}">... more</a>
- {% endif %}</p>
- <div class="date">
- <a>Published by: <a style="font-weight: bold;" href="{% url 'profile' pk=user.pk %}" >{{ post.author }}</a></a><br>
- <a>Published at: {{ post.published_date }}</a><br>
- <a>Category: {{ post.category }}</a><br>
- <a>Tag(s): {{ post.tag }}</a>
- </div>
- </div>
- {% endfor %}
- {% endif %}
- {% endblock %}
- def globalsearch_elastic(request):
- keywords = request.GET.get('qs')
- if keywords:
- posts = PostDocument.search().query("match", title=keywords)
- else:
- posts = ''
- return render(request, 'myproject/search_results_elastic.html', {'object_list':posts})
- ...
- class Post(models.Model):
- author = models.ForeignKey('myproject_Accounts.User', on_delete=models.CASCADE)
- title = models.CharField(max_length=42)
- content = models.TextField(max_length=5000)
- tag = models.CharField(max_length=50, blank=True)
- category = models.ForeignKey(Category, verbose_name="Category", on_delete=models.CASCADE, null=True)
- postattachment = fields.FileField(blank=True ,null=True, upload_to=get_file_path_user_uploads)
- postcover = fields.ImageField(null=True, upload_to=get_file_path_user_uploads, dependencies=[
- FileDependency(processor=ImageProcessor(format='JPEG', quality=90, scale={'max_width': 700, 'max_height': 700}))])
- created_date = models.DateField(auto_now_add=True)
- published_date = models.DateField(blank=True, null=True)
- ...
Add Comment
Please, Sign In to add comment