Skip to main content
# AutoComplete for ForeignKey and ManyToManyField
uses same syntax as the search for django-admin

requirements
* query.js (http://jquery.com/)
* query.autocomplete.js

## Example


use a fairly simple
*models.py*
class Type (models.Model):
title = models.CharField()

class Celebrity(models.Model):
name = models.CharField()

class Film(models.Model):
type = models.ForeignKey( Type )
director= models.ManyToManyField( Celebrity, related_name="director")
actor = models.ManyToManyField( Celebrity, related_name="actor")

in m2m field need to specify related_name

*admin.py*
from apps.autocomplete.widgets import *

class FilmAdmin(AutocompleteModelAdmin):
related_search_fields = {

'type': ('title',),
'actor': ('^name',),
'director': ('^name',),
}
admin.site.register( Film, FilmAdmin )

"related_search_fields" parameter is used to specify on what fields you want to search 'actor' and 'director' ties are the names given in "related_name" query syntax is similar to [searching in admin panel](http://docs.djangoproject.com/en/dev/ref/contrib/admin/#django.contrib.admin.ModelAdmin.search_fields)

I use the " 'actor': ('^name',) " operator ^ means the beginning of the field. and eventually will be formed about the substitution request form For example, if related_search_fieldsis set to ('^name',') and a user searches for john lennon, Django will do the equivalent of this SQL WHERE clause:

WHERE name ILIKE 'john%' AND name ILIKE 'lennon%'

Metadata

Release files for django_autocomplete_foreignkey 0.0.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for django_autocomplete_foreignkey 0.0.1
File Size Uploaded Provenance
django_autocomplete_foreignkey-0.0.1.tar.gz 11.7 kB Without provenance Details

Release files / django_autocomplete_foreignkey-0.0.1.tar.gz

Download URL django_autocomplete_foreignkey-0.0.1.tar.gz
Size 11.7 kB
Tags Source
SHA-256 checksum
How to use checksums
73b040e8fab18653aa04796a4ca6d433f7e41d6040a748713155ae6bf9f8fe97
BLAKE2b-256 checksum
How to use checksums
62a7250022fa3bb9ba70a19fb9131ee1afda56d2f969dc9293a529baa4c19d66
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Security for django_autocomplete_foreignkey 0.0.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.0.1 This release

1 release file No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page