django-ajax-filtered-fields

Django fields for many to many and foreign key ajax filtered relations
Download

django-ajax-filtered-fields Ranking & Summary

Advertisement

  • Rating:
  • License:
  • MIT/X Consortium Lic...
  • Price:
  • FREE
  • Publisher Name:
  • Francesco Banconi
  • Publisher web site:
  • http://code.google.com/u/francesco.banconi/

django-ajax-filtered-fields Tags


django-ajax-filtered-fields Description

Django fields for many to many and foreign key ajax filtered relations django-ajax-filtered-fields contains Django fields which may be used in a many to many or foreign key relation, where the user may want to apply filters to the listed objects, because of they being too many, or just for usability reasons.Technical detailsWhen the user clicks on the chosen filter, an Ajax request is sent. It returns the matching elements in JSON format. The jQuery Javascript library is used.InstallationThe ajax_filtered_fields package, included in the distribution, should be placed on the Python path.UsageAs a usage example, let's put the MyModel model in a many to many relation with the RelatedModel one, via the related_models field.copy to your media directory the Javascript file ajax_filtered_fields.jsincluded in media/js/ within the distribution;add this line to your Django project's urls.py:(r'^ajax_filtered_fields/', include('ajax_filtered_fields.urls')),in the model form, choose the field you want to use, reference the formerly copied Javascript file, the jQuery library and the django admin's Javascript code that mutates the select widget into a selectfilter one:from ajax_filtered_fields.forms import AjaxManyToManyFieldfrom django.conf import settings class MyModelForm(forms.ModelForm): # lookups explained below related_objects = AjaxManyToManyField(RelatedModel, lookups) class Meta: model = Model class Media: js = ( settings.ADMIN_MEDIA_PREFIX + "js/SelectBox.js", settings.ADMIN_MEDIA_PREFIX + "js/SelectFilter2.js", '/path/to/javascripts/jquery.js', '/path/to/javascripts/ajax_filtered_fields.js', )if the form is being used outside of the auto generated django admin, you have to load several django admin's Javascript files from the page where the field will be shown:{% load adminmedia %}< script type="text/javascript" src="/admin/jsi18n/" >< /script >< script type="text/javascript" src="{% admin_media_prefix %}js/core.js" >< /script >if you want i18n for ManyToManyByLetter, ForeignKeyByLetter, ManyToManyByStatus and ForeignKeyByStatus fields (see below for details about available fields), add 'ajax_filtered_fields'to the INSTALLED_APPS in your settings.py. The only languages currently available are English and Italian. Requirements: · Django · Python


django-ajax-filtered-fields Related Software