summaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
Diffstat (limited to 'app')
-rw-r--r--app/links/admin.py6
-rw-r--r--app/links/autocomplete_light_registry.py24
-rw-r--r--app/links/forms.py10
3 files changed, 38 insertions, 2 deletions
diff --git a/app/links/admin.py b/app/links/admin.py
index ff75a09..b772d24 100644
--- a/app/links/admin.py
+++ b/app/links/admin.py
@@ -1,10 +1,12 @@
from django.contrib import admin
from utils.widgets import TagListFilter
-from links.models import Link
-
+import autocomplete_light
+from .models import Link
+from .forms import LinkForm
class LinkAdmin(admin.ModelAdmin):
+ form = LinkForm
list_display = ('title', 'admin_link', 'pub_date', 'status')
search_fields = ['title', 'description', 'url']
list_filter = ['status', TagListFilter]
diff --git a/app/links/autocomplete_light_registry.py b/app/links/autocomplete_light_registry.py
new file mode 100644
index 0000000..0781848
--- /dev/null
+++ b/app/links/autocomplete_light_registry.py
@@ -0,0 +1,24 @@
+import autocomplete_light.shortcuts as al
+from taggit.models import Tag
+
+# This will generate a PersonAutocomplete class
+al.register(Tag,
+ # Just like in ModelAdmin.search_fields
+ search_fields=['name'],
+ attrs={
+ # This will set the input placeholder attribute:
+ 'placeholder': 'Tags...',
+ # This will set the yourlabs.Autocomplete.minimumCharacters
+ # options, the naming conversion is handled by jQuery
+ 'data-autocomplete-minimum-characters': 1,
+},
+ # This will set the data-widget-maximum-values attribute on the
+ # widget container element, and will be set to
+ # yourlabs.Widget.maximumValues (jQuery handles the naming
+ # conversion).
+ widget_attrs={
+ 'data-widget-maximum-values': 4,
+ # Enable modern-style widget !
+ 'class': 'modern-style',
+ },
+)
diff --git a/app/links/forms.py b/app/links/forms.py
new file mode 100644
index 0000000..ca6205b
--- /dev/null
+++ b/app/links/forms.py
@@ -0,0 +1,10 @@
+from django import forms
+import autocomplete_light
+from autocomplete_light.contrib.taggit_field import TaggitField, TaggitWidget
+from .models import Link
+
+class LinkForm(forms.ModelForm):
+ tags = TaggitField(widget=TaggitWidget('TagAutocomplete'))
+ class Meta:
+ fields = '__all__'
+ model = Link