Autocomplete Django extensions admin works with IDs, not text
In django admin I am trying to get my users to look for name, autocomplete the field and when the selected instance of the new model will store the id of the selected school, not the name.
I was able to get the autocomplete fields on the unitid using django-extensions, but I want users to be able to search for the organization name and register the unitid.
My models:
models.py
class IPED(models.Model):
unitid = models.IntegerField(unique=True)
instnm = models.CharField(max_length=300)
class LISTING(models.Model):
listid = models.IntegerField(unique=True)
unitid = models.ForeignKey(IPED, to_field='unitid')
notes = models.CharField(max_length=600)
admin.py
from django_extensions.admin import ForeignKeyAutocompleteAdmin
class ListAdmin(ForeignKeyAutocompleteAdmin):
list_display = ('listid','unitid',)
related_search_fields = {
'unitid': ('unitid','instnm'), #when searching for a unitid, this plugin works. If I search for an instnm, it does not.
}
+3
source to share
No one has answered this question yet
Check out similar questions: