django-completion

Autocompletion for Django apps
Download

django-completion Ranking & Summary

Advertisement

  • Rating:
  • License:
  • MIT/X Consortium Lic...
  • Publisher Name:
  • Charles Leifer

django-completion Tags


django-completion Description

Autocompletion for Django apps django-completion is a Django app that offers autocompletion.Supports the following backends: * solr * postgres * redis (pretty experimental)usage follows typical django registration-y pattern:from django.db import modelsfrom completion import siteclass Blog(models.Model): title = models.CharField(max_length=255) pub_date = models.DateTimeField() content = models.TextField() published = models.BooleanField(default=True) def get_absolute_url(self): return reverse('blog_detail', args=)class BlogProvider(AutocompleteProvider): def get_title(self, obj): return obj.title def get_pub_date(self, obj): return datetime.datetime(2010, 1, 1) def get_data(self, obj): return {'stored_title': obj.title, 'url': obj.get_absolute_url()} def get_queryset(self): return self.model._default_manager.filter(published=True)site.register(Blog, BlogProvider)The Blog model is now ready for autocomplete, but the objects must be stored before they can be returned:>>> from completion import site>>> site.store_providers()>>> site.suggest('tes')>>> site.suggest('testing')Objects can be added or removed at any time from the index:>>> site.store_object(some_blog_instance)>>> site.remove_object(some_other_obj)ConfiguringThe AUTOCOMPLETE_BACKEND setting allows you to specify which backend to use for autocomplete. The options are: * completion.backends.postgres_backend.PostgresAutocomplete * completion.backends.redis_backend.RedisAutocomplete * completion.backends.solr_backend.SolrAutocompleteConfiguring RedisMake sure that you have Redis and redis-py installed.Add something like the following to your settings file, where the connection string is < host name >:< port >:< database >AUTOCOMPLETE_REDIS_CONNECTION = 'localhost:6379:0'Configuring SolrMake sure that you have Solr and pysolr installed.Add something like this to your settings file:AUTOCOMPLETE_SOLR_CONNECTION = 'http://localhost:8080/solr/autocomplete-core/'Additionally, if you end up using Solr (which I'd recommend!), you will need to ensure you have the correct field definitions in your solr schema. A sample schema can be generated for you automatically, by running:django-admin.py autocomplete_schemaThis will drop a file named schema.xml in your current directory.Installation:python setup.py installORput the completion folder on your python-path Requirements: · Python


django-completion Related Software