Skip to content

Commit

Permalink
Simple taggit_autocomplete app.
Browse files Browse the repository at this point in the history
This app shows how to integrate django-autocomple-light with django-taggit.
  • Loading branch information
sebastianrmirz authored and Sebastian committed Jan 14, 2014
1 parent 714d1de commit a2967bb
Show file tree
Hide file tree
Showing 10 changed files with 59 additions and 1 deletion.
4 changes: 4 additions & 0 deletions test_project/taggit_autocomplete/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
App to show support for django-taggit.

Make sure to run ./manage.py migrate to create taggit tables.

Empty file.
9 changes: 9 additions & 0 deletions test_project/taggit_autocomplete/admin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
from django.contrib import admin
from models import TaggitDemo
from forms import TaggitDemoForm

class TaggitDemoAdmin(admin.ModelAdmin):
model = TaggitDemo
form = TaggitDemoForm

admin.site.register(TaggitDemo, TaggitDemoAdmin)
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import autocomplete_light
from taggit.models import Tag

autocomplete_light.register(Tag)

13 changes: 13 additions & 0 deletions test_project/taggit_autocomplete/forms.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
from django import forms
import autocomplete_light
from autocomplete_light.contrib import taggit_tagfield
from models import TaggitDemo

class TaggitDemoForm(forms.ModelForm):
tags = taggit_tagfield.TagField(widget=taggit_tagfield.TagWidget('TagAutocomplete'))
class Meta:
model = TaggitDemo
widgets = {
'tags': autocomplete_light.TextWidget('TagAutocomplete'),
}

10 changes: 10 additions & 0 deletions test_project/taggit_autocomplete/models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
from django.db import models
from taggit.managers import TaggableManager

class TaggitDemo(models.Model):
name = models.CharField(max_length=255)
tags = TaggableManager(blank=True)

def __unicode__(self):
return self.name

7 changes: 7 additions & 0 deletions test_project/taggit_autocomplete/urls.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
from django.conf.urls import patterns, url
from views import TaggitDemoCreate

urlpatterns = patterns('',
url(r'^create/$', TaggitDemoCreate.as_view()),
)

8 changes: 8 additions & 0 deletions test_project/taggit_autocomplete/views.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from django.views.generic.edit import CreateView
from models import TaggitDemo
from forms import TaggitDemoForm

class TaggitDemoCreate(CreateView):
model = TaggitDemo
form_class = TaggitDemoForm

1 change: 1 addition & 0 deletions test_project/test_project/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@
'default_template_autocomplete',
'ajax_create',
'taggit',
'taggit_autocomplete',
)

# A sample logging configuration. The only tangible logging
Expand Down
3 changes: 2 additions & 1 deletion test_project/test_project/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@
(r'^i18n/', include('django.conf.urls.i18n')),
(r'^just_javascript/$', generic.TemplateView.as_view(
template_name='just_javascript.html')),
(r'^$', generic.TemplateView.as_view(template_name='index.html'))
(r'^$', generic.TemplateView.as_view(template_name='index.html')),
url('r^taggit_autocomplete/', include('taggit_autocomplete.urls')),
)

if hvad:
Expand Down

0 comments on commit a2967bb

Please sign in to comment.