summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--app/links/admin.py6
-rw-r--r--app/links/autocomplete_light_registry.py24
-rw-r--r--app/links/forms.py10
-rw-r--r--config/base_urls.py1
-rw-r--r--design/templates/admin/base.html2
5 files changed, 41 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
diff --git a/config/base_urls.py b/config/base_urls.py
index 26a2081..b5ee0db 100644
--- a/config/base_urls.py
+++ b/config/base_urls.py
@@ -35,6 +35,7 @@ urlpatterns = [
]
urlpatterns += [
+ url(r'^autocomplete/', include('autocomplete_light.urls')),
url(r'^admin/build/.*', builder.views.do_build),
url(r'^admin/', include(admin.site.urls),),
url(r'^sitemap.xml$', sitemap, {'sitemaps': sitemaps}),
diff --git a/design/templates/admin/base.html b/design/templates/admin/base.html
index 455d0d2..0af7cc7 100644
--- a/design/templates/admin/base.html
+++ b/design/templates/admin/base.html
@@ -3,12 +3,14 @@
<head>
<title>{% block title %}{% endblock %}</title>
<link rel="stylesheet" type="text/css" href="{% block stylesheet %}{% static "admin/css/base.css" %}{% endblock %}" />
+<script type="text/javascript" src="/static/admin/js/jquery.js"></script>
{% block extrastyle %}{% endblock %}
<!--[if lte IE 7]><link rel="stylesheet" type="text/css" href="{% block stylesheet_ie %}{% static "admin/css/ie.css" %}{% endblock %}" /><![endif]-->
{% if LANGUAGE_BIDI %}<link rel="stylesheet" type="text/css" href="{% block stylesheet_rtl %}{% static "admin/css/rtl.css" %}{% endblock %}" />{% endif %}
<script type="text/javascript">window.__admin_media_prefix__ = "{% filter escapejs %}{% static "admin/" %}{% endfilter %}";</script>
{% block extrahead %}{% endblock %}
{% block blockbots %}<meta name="robots" content="NONE,NOARCHIVE" />{% endblock %}
+{% include 'autocomplete_light/static.html' %}
</head>
{% load i18n %}