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
python-2.7 django


source to share


No one has answered this question yet

Check out similar questions:

ten
Make django admin to show no more than 100 characters in list results.
five
django - inlineformset_factory with multiple foreign keys
4
Radio buttons in django admin
3
How to expose some specific model_b fields based on the model_a field?
2
How to set dynamic initial values ​​in a django modelform field
1
How to define mode with regular ForeignKey in Django
1
Django south migration error with unique field in postgresql database
1
Django - queries over relationships
1
Product catalog: filter by parameters
1
Show subclass information in django display_list



All Articles
Loading...
X
Show
Funny
Dev
Pics