Package: django-smart-selects-fix
Django Smart SelectsCURRENTLY UNMAINTAINED - Please contact digi604 if you would like to maintain this appThis package allows you to quickly filter or group "chained" models by adding a custom foreign key or many to many field to your models. This will use an AJAX query to load only the applicable chained objects.Warning: The AJAX endpoint enforces no permissions by default.  This means thatany model with a chained field will be world readable. If you would like more control over this permission, thedjango-autocomplete-lightpackage is a great, high-quality package that enables the same functionality with permission checks.Chained SelectsGiven the following model:classContinent(models.Model):name=models.CharField(max_length=255)classCountry(models.Model):continent=models.ForeignKey(Continent)name=models.CharField(max_length=255)classLocation(models.Model):continent=models.ForeignKey(Continent)country=models.ForeignKey(Country)area=models.ForeignKey(Area)city=models.CharField(max_length=50)street=models.CharField(max_length=100)Once you select a continent, if you want only the countries on that continent to be available, you can use aChainedForeignKeyon theLocationmodel:fromsmart_selects.db_fieldsimportChainedForeignKeyclassLocation(models.Model):continent=models.ForeignKey(Continent)country=ChainedForeignKey(Country,chained_field="continent",chained_model_field="continent",show_all=False,auto_choose=True,sort=True)area=ForeignKey(Area)city=models.CharField(max_length=50)street=models.CharField(max_length=100)ChainedForeignKey optionschained_field (required)Thechained_fieldindicates the field on the same model that should be chained to. In theContinent,Country,Locationexample,chained_fieldis the name of the fieldcontinentin modelLocation.classLocation(models.Model)continent=models.ForeignKey(Continent)chained_model_field (required)Thechained_model_fieldindicates the field of the chained model that corresponds to the model linked to by thechained_field. In theContinent,Country,Locationexample,chained_model_fieldis the name of fieldcontinentin ModelCountry.classCountry(models.Model):continent=models.ForeignKey(Continent)show_all (optional)show_allindicates if only the filtered results should be shown or if you also want to display the other results further down.auto_choose (optional)auto_chooseindicates if auto select the choice when there is only one available choice.sort(optional)sortindicates if the result set should be sorted lexicographically or not. Disable if you want to use theModel.orderingoption. Defaults toTrue.Chained ManyToMany SelectsTheChainedManyToManyFieldworks as you would expect:fromsmart_selects.db_fieldsimportChainedManyToManyFieldclassPublication(models.Model):name=models.CharField(max_length=255)classWriter(models.Model):name=models.CharField(max_length=255)publications=models.ManyToManyField('Publication',blank=True,null=True)classBook(models.Model):publication=models.ForeignKey(Publication)writer=ChainedManyToManyField(Writer,chained_field="publication",chained_model_field="publications")name=models.CharField(max_length=255)Using chained fields in the adminDonotspecify the field in theModelAdminfilter_horizontallist. Instead, simply passhorizontal=Trueto theChainedManyToManyField:fromsmart_selects.db_fieldsimportChainedManyToManyFieldclassPublication(models.Model):name=models.CharField(max_length=255)classWriter(models.Model):name=models.CharField(max_length=255)publications=models.ManyToManyField('Publication',blank=True,null=True)classBook(models.Model):publication=models.ForeignKey(Publication)writer=ChainedManyToManyField(Writer,horizontal=True,verbose_name='writer',chained_field="publication",chained_model_field="publications")name=models.CharField(max_length=255)ChainedManyToManyField optionschained_field(required)Thechained_fieldindicates the field on the same model that should be chained to. In thePublication,Writer,Bookexample,chained_fieldis the name of the fieldpublicationin modelBook.classBook(models.Model):publication=models.ForeignKey(Publication)chained_model_field(required)Thechained_model_fieldindicates the field of the chained model that corresponds to the model linked to by thechained_field. In thePublication,Writer,Bookexample,chained_model_fieldis the name of fieldpublicationsinWritermodel.classWriter(models.Model):publications=models.ManyToManyField('Publication',blank=True,null=True)auto_choose(optional)auto_chooseindicates if auto select the choice when there is only one available choice.horizontal(optional)This option will mixin Django'sFilteredSelectMultipleto work in the Django admin as you expectGrouped SelectsIf you have the following model:classCountry(models.Model):continent=models.ForeignKey(Continent)classLocation(models.Model):continent=models.ForeignKey(Continent)country=models.ForeignKey(Country)And you want to group countries by their continent in the HTML select list, you can use aGroupedForeignKey:fromsmart_selects.db_fieldsimportGroupedForeignKeyclassLocation(models.Model):continent=models.ForeignKey(Continent)country=GroupedForeignKey(Country,"continent")InstallationAddsmart_selectsto yourINSTALLED_APPSAdd thesmart_selectsurls into your project'surls.py. This is needed for theChained SelectsandChained ManyToMany Selects. For example:urlpatterns=patterns('',url(r'^admin/',include(admin.site.urls)),url(r'^chaining/',include('smart_selects.urls')),)You will also need to include jQuery in every page that includes a field fromsmart_selects, or setJQUERY_URL = Truein your project'ssettings.py.SettingsJQUERY_URL:   jQuery 2.2.0 is loaded from Google's CDN if this is set toTrue. If you would prefer to
use a different version put the full URL here. SetJQUERY_URL = Falseto disable loading jQuery altogether.USE_DJANGO_JQUERY:   By default,smart_selectsloads jQuery from Google's CDN. However, it can use jQuery from Django's
admin area. SetUSE_DJANGO_JQUERY = Trueto enable this behaviour.TODOAdd permission checks to enable users to restrict who can use the chained fields.Add aChainedCheckboxSelectMultiplewidget and adjustchainedm2m.jsandchainedfk.jsto build checkboxes in that case