diff --git a/.idea/jsLibraryMappings.xml b/.idea/jsLibraryMappings.xml
index 2a5d32266..e72781fbe 100644
--- a/.idea/jsLibraryMappings.xml
+++ b/.idea/jsLibraryMappings.xml
@@ -1,6 +1,6 @@
-
+
\ No newline at end of file
diff --git a/.idea/recipes.iml b/.idea/recipes.iml
index 43fb334e4..f030f84da 100644
--- a/.idea/recipes.iml
+++ b/.idea/recipes.iml
@@ -18,14 +18,14 @@
-
-
+
+
diff --git a/cookbook/forms.py b/cookbook/forms.py
index 8bbf18778..1aaaf166a 100644
--- a/cookbook/forms.py
+++ b/cookbook/forms.py
@@ -4,6 +4,8 @@ from django.utils.translation import gettext as _
from django import forms
from .models import *
+from dal import autocomplete
+
class RecipeForm(forms.ModelForm):
class Meta:
@@ -73,8 +75,8 @@ class EditRecipeForm(forms.ModelForm):
'path': _('Path'),
}
- help_texts = {
- 'keywords': _('Ctrl+Click to select multiple keywords'),
+ widgets = {
+ 'keywords': autocomplete.ModelSelect2Multiple(url='dal_keyword')
}
def __init__(self, *args, **kwargs):
diff --git a/cookbook/helper/__init__.py b/cookbook/helper/__init__.py
index e69de29bb..bde2ba3a3 100644
--- a/cookbook/helper/__init__.py
+++ b/cookbook/helper/__init__.py
@@ -0,0 +1,2 @@
+from cookbook.helper.dal import *
+from cookbook.helper.dropbox import *
diff --git a/cookbook/helper/dal.py b/cookbook/helper/dal.py
new file mode 100644
index 000000000..04dd5b2d6
--- /dev/null
+++ b/cookbook/helper/dal.py
@@ -0,0 +1,16 @@
+from dal import autocomplete
+
+from cookbook.models import Keyword
+
+
+class KeywordAutocomplete(autocomplete.Select2QuerySetView):
+ def get_queryset(self):
+ if not self.request.user.is_authenticated:
+ return Keyword.objects.none()
+
+ qs = Keyword.objects.all()
+
+ if self.q:
+ qs = qs.filter(name__istartswith=self.q)
+
+ return qs
diff --git a/cookbook/templates/base.html b/cookbook/templates/base.html
index d548a6d9c..b168fe5c4 100644
--- a/cookbook/templates/base.html
+++ b/cookbook/templates/base.html
@@ -7,8 +7,9 @@
{% endblock %}
-
diff --git a/cookbook/urls.py b/cookbook/urls.py
index 3639596df..e44bacf15 100644
--- a/cookbook/urls.py
+++ b/cookbook/urls.py
@@ -2,6 +2,7 @@ from django.urls import path
from .views import *
from cookbook.views import api
+from cookbook.helper import dal
urlpatterns = [
path('', views.index, name='index'),
@@ -30,5 +31,7 @@ urlpatterns = [
path('api/get_file_link//', api.get_file_link, name='api_get_file_link'),
path('api/sync_all/', api.dropbox_sync, name='api_dropbox_sync'),
+ path('dal/keyword/', dal.KeywordAutocomplete.as_view(), name='dal_keyword'),
+
]
diff --git a/recipes/settings.py b/recipes/settings.py
index 59d904424..2ae2ae644 100644
--- a/recipes/settings.py
+++ b/recipes/settings.py
@@ -33,6 +33,8 @@ MESSAGE_TAGS = {
# Application definition
INSTALLED_APPS = [
+ 'dal',
+ 'dal_select2',
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
diff --git a/requirements.txt b/requirements.txt
index ac1785f11..9af8c3106 100644
--- a/requirements.txt
+++ b/requirements.txt
@@ -1,6 +1,8 @@
+six
requests
django
django-tables2
django-filter
django-crispy-forms
-djangorestframework
\ No newline at end of file
+djangorestframework
+django-autocomplete-light
\ No newline at end of file