basic multiselect working
This commit is contained in:
2
.idea/jsLibraryMappings.xml
generated
2
.idea/jsLibraryMappings.xml
generated
@ -1,6 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="JavaScriptLibraryMappings">
|
||||
<file url="file://$PROJECT_DIR$" libraries="{bootstrap, jquery-3.2.1.slim, popper}" />
|
||||
<file url="file://$PROJECT_DIR$" libraries="{bootstrap, jquery-3.2.1, jquery-3.2.1.slim, jquery-3.3.1, popper}" />
|
||||
</component>
|
||||
</project>
|
4
.idea/recipes.iml
generated
4
.idea/recipes.iml
generated
@ -18,14 +18,14 @@
|
||||
</content>
|
||||
<orderEntry type="jdk" jdkName="Python 3.6 (recipes)" jdkType="Python SDK" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
<orderEntry type="library" name="jquery-3.1.1.slim" level="application" />
|
||||
<orderEntry type="library" name="tether" level="application" />
|
||||
<orderEntry type="library" name="bootstrap" level="application" />
|
||||
<orderEntry type="library" name="jquery-3.2.1.slim" level="application" />
|
||||
<orderEntry type="library" name="popper" level="application" />
|
||||
<orderEntry type="library" name="jquery-3.2.1.slim" level="application" />
|
||||
<orderEntry type="library" name="popper" level="application" />
|
||||
<orderEntry type="library" name="bootstrap" level="application" />
|
||||
<orderEntry type="library" name="jquery-3.2.1" level="application" />
|
||||
<orderEntry type="library" name="jquery-3.3.1" level="application" />
|
||||
</component>
|
||||
<component name="TemplatesService">
|
||||
<option name="TEMPLATE_CONFIGURATION" value="Django" />
|
||||
|
@ -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):
|
||||
|
@ -0,0 +1,2 @@
|
||||
from cookbook.helper.dal import *
|
||||
from cookbook.helper.dropbox import *
|
||||
|
16
cookbook/helper/dal.py
Normal file
16
cookbook/helper/dal.py
Normal file
@ -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
|
@ -7,8 +7,9 @@
|
||||
{% endblock %}</title>
|
||||
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css"
|
||||
integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
|
||||
<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js"
|
||||
integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN"
|
||||
<script
|
||||
src="https://code.jquery.com/jquery-3.3.1.min.js"
|
||||
integrity="sha256-FgpCb/KJQlLNfOu91ta32o/NMZxltwRo8QtmkMRdAu8="
|
||||
crossorigin="anonymous"></script>
|
||||
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js"
|
||||
integrity="sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q"
|
||||
@ -18,7 +19,14 @@
|
||||
crossorigin="anonymous"></script>
|
||||
|
||||
<style>
|
||||
@media (max-width:1025px) { .container { width: 95% !important; margin-left: 20px !important; margin-right: 20px !important;max-width: 1200px !important;} }
|
||||
@media (max-width: 1025px) {
|
||||
.container {
|
||||
width: 95% !important;
|
||||
margin-left: 20px !important;
|
||||
margin-right: 20px !important;
|
||||
max-width: 1200px !important;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
|
@ -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/<int:recipe_id>/', 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'),
|
||||
|
||||
]
|
||||
|
||||
|
@ -33,6 +33,8 @@ MESSAGE_TAGS = {
|
||||
# Application definition
|
||||
|
||||
INSTALLED_APPS = [
|
||||
'dal',
|
||||
'dal_select2',
|
||||
'django.contrib.admin',
|
||||
'django.contrib.auth',
|
||||
'django.contrib.contenttypes',
|
||||
|
@ -1,6 +1,8 @@
|
||||
six
|
||||
requests
|
||||
django
|
||||
django-tables2
|
||||
django-filter
|
||||
django-crispy-forms
|
||||
djangorestframework
|
||||
django-autocomplete-light
|
Reference in New Issue
Block a user