diff --git a/bookmarks/queries.py b/bookmarks/queries.py index 3f659b3..5a29cce 100644 --- a/bookmarks/queries.py +++ b/bookmarks/queries.py @@ -29,17 +29,25 @@ def query_bookmarks(user: User, query_string: str): # Filter for user query_set = query_set.filter(owner=user) - # Split query into keywords + # Split query into search terms and tags keywords = query_string.strip().split(' ') keywords = [word for word in keywords if word] - # Filter for each keyword - for word in keywords: + search_terms = [word for word in keywords if word[0] != '#'] + tag_names = [word[1:] for word in keywords if word[0] == '#'] + + # Filter for search terms and tags + for term in search_terms: query_set = query_set.filter( - Q(title__contains=word) - | Q(description__contains=word) - | Q(website_title__contains=word) - | Q(website_description__contains=word) + Q(title__contains=term) + | Q(description__contains=term) + | Q(website_title__contains=term) + | Q(website_description__contains=term) + ) + + for tag_name in tag_names: + query_set = query_set.filter( + tags__name=tag_name ) # Sort by modification date diff --git a/bookmarks/styles/bookmarks.scss b/bookmarks/styles/bookmarks.scss index 3ea3055..7f3c456 100644 --- a/bookmarks/styles/bookmarks.scss +++ b/bookmarks/styles/bookmarks.scss @@ -1,3 +1,10 @@ +.bookmarks-page { + + .search input[type=search] { + width: 200px; + } +} + ul.bookmark-list { list-style: none; diff --git a/bookmarks/templates/bookmarks/index.html b/bookmarks/templates/bookmarks/index.html index 86eabe8..29c2f09 100644 --- a/bookmarks/templates/bookmarks/index.html +++ b/bookmarks/templates/bookmarks/index.html @@ -3,7 +3,7 @@ {% load bookmarks %} {% block content %} -
+
{# Bookmark list #}
@@ -13,7 +13,7 @@