Autocomplete pro Skola (a pozdeji pro dalsi)

This commit is contained in:
Tomas Gavenciak 2015-05-17 07:28:55 +02:00
parent 50c50c378b
commit d55b3ad3a9
7 changed files with 44 additions and 6 deletions

View file

@ -78,13 +78,9 @@ TEMPLATE_CONTEXT_PROCESSORS = (
)
INSTALLED_APPS = (
'admin_tools',
'admin_tools.theming',
'admin_tools.menu',
'admin_tools.dashboard',
# Basic
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
@ -104,6 +100,13 @@ INSTALLED_APPS = (
'mamweb',
'seminar',
# Prvni:
'autocomplete_light',
'admin_tools',
'admin_tools.theming',
'admin_tools.menu',
'admin_tools.dashboard',
'django.contrib.admin',
)
DEBUG_TOOLBAR_CONFIG = {

View file

@ -0,0 +1,7 @@
{% extends "admin/base.html" %}
{% load staticfiles %}
{% block extrahead %}
<script src="{% static 'js/jquery-1.11.1.js' %}"></script>
{% include 'autocomplete_light/static.html' %}
{% endblock %}

View file

@ -10,6 +10,7 @@
<link href="{% static 'css/mamweb.css' %}" rel="stylesheet">
<link href="{% static 'css/prettyPhoto.css' %}" rel="stylesheet" type="text/css" media="screen" charset="utf-8" />
<script src="{% static 'js/jquery-1.11.1.js' %}"></script>
{% include 'autocomplete_light/static.html' %}
</head>
<body class='{% if True %}org-logged-in{% endif %}'>
<!-- TODO: only on org login -->

View file

@ -10,6 +10,7 @@ urlpatterns = i18n_patterns('',
url(r'^admin/', include(admin.site.urls)), # NOQA
url(r'^admin_tools/', include('admin_tools.urls')),
url(r'^ckeditor/', include('ckeditor.urls')),
url(r'^autocomplete/', include('autocomplete_light.urls')),
url(r'^', include('seminar.urls')),
url(r'^$', TemplateView.as_view(template_name='home.html'), name='home'),
)

View file

@ -19,6 +19,7 @@ django-solo==1.1.0
django-ckeditor==4.4.7
django-admin-tools==0.5.2
django-taggit==0.14.0
django-autocomplete-light==2.1.1
# debug tools/extensions

View file

@ -6,7 +6,7 @@ from solo.admin import SingletonModelAdmin
from ckeditor.widgets import CKEditorWidget
from seminar.models import Skola, Resitel, Rocnik, Cislo, Problem, Reseni, PrilohaReseni, Nastaveni, Soustredeni
import autocomplete_light
### Nastaveni
admin.site.register(Nastaveni, SingletonModelAdmin)
@ -29,6 +29,7 @@ admin.site.register(Skola, SkolaAdmin)
### Resitel
class ResitelAdmin(reversion.VersionAdmin):
form = autocomplete_light.modelform_factory(Resitel)
fieldsets = [
(None, {'fields': ['jmeno', 'prijmeni', 'user']}),
(u'Škola', {'fields': ['skola', 'rok_maturity']}),

View file

@ -0,0 +1,24 @@
import autocomplete_light
from models import Skola
# This will generate a PersonAutocomplete class
autocomplete_light.register(Skola,
# Just like in ModelAdmin.search_fields
search_fields=['nazev', 'mesto', 'ulice'],
attrs={
# This will set the input placeholder attribute:
'placeholder': 'Skola',
# 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': 15,
# Enable modern-style widget !
'class': 'modern-style',
},
)