diff options
author | luxagraf <sng@luxagraf.net> | 2017-07-16 09:40:48 -0600 |
---|---|---|
committer | luxagraf <sng@luxagraf.net> | 2017-07-16 09:40:48 -0600 |
commit | d295b55359e0f507775aba62f29a76de077bfca1 (patch) | |
tree | afc327d4193dabfbddd50b614e1dd1577b230362 /app | |
parent | a4335acd6312620a40898be33042e3d4de762f0b (diff) |
Updated to django autocomplete v3
Diffstat (limited to 'app')
-rw-r--r-- | app/links/admin.py | 1 | ||||
-rw-r--r-- | app/links/forms.py | 19 | ||||
-rw-r--r-- | app/links/views.py | 1 | ||||
-rw-r--r-- | app/utils/views.py | 17 |
4 files changed, 30 insertions, 8 deletions
diff --git a/app/links/admin.py b/app/links/admin.py index 1f45f1e..c1c0bdb 100644 --- a/app/links/admin.py +++ b/app/links/admin.py @@ -6,7 +6,6 @@ from django.contrib.admin import helpers from django.http import HttpResponseRedirect from utils.widgets import TagListFilter -import autocomplete_light from .models import Link from .forms import LinkForm diff --git a/app/links/forms.py b/app/links/forms.py index ca6205b..80a7c50 100644 --- a/app/links/forms.py +++ b/app/links/forms.py @@ -1,10 +1,17 @@ from django import forms -import autocomplete_light -from autocomplete_light.contrib.taggit_field import TaggitField, TaggitWidget +import dal +from dal_select2_taggit.widgets import TaggitSelect2 from .models import Link -class LinkForm(forms.ModelForm): - tags = TaggitField(widget=TaggitWidget('TagAutocomplete')) +from dal import autocomplete + + +class LinkForm(autocomplete.FutureModelForm): class Meta: - fields = '__all__' - model = Link + model = Link + fields = ('tags',) + widgets = { + 'tags': autocomplete.TaggitSelect2( + 'tag-autocomplete' + ) + } diff --git a/app/links/views.py b/app/links/views.py index 36ccca3..b00d32c 100644 --- a/app/links/views.py +++ b/app/links/views.py @@ -4,7 +4,6 @@ from utils.views import PaginatedListView from .models import Link from taggit.models import Tag - class LinkListView(PaginatedListView): model = Link template_name = 'archives/links.html' diff --git a/app/utils/views.py b/app/utils/views.py index c5f3f59..fe0db4b 100644 --- a/app/utils/views.py +++ b/app/utils/views.py @@ -35,3 +35,20 @@ def insert_image(request): ) return render_to_response('admin/insert_images.html', {'object_list': object_list, 'textarea_id': request.GET['textarea']}, context_instance=RequestContext(request)) + +from taggit.models import Tag + +from dal import autocomplete + +class TagAutocomplete(autocomplete.Select2QuerySetView): + def get_queryset(self): + # Don't forget to filter out results depending on the visitor ! + if not self.request.user.is_authenticated(): + return Tag.objects.none() + + qs = Tag.objects.all() + + if self.q: + qs = qs.filter(name__istartswith=self.q) + + return qs |