0

I have a django model as below:

class Words(models.Model):
    bare = models.CharField(max_length=100)
    accented = models.CharField(max_length=100)
    derived_from_word = models.ForeignKey('self', models.DO_NOTHING, blank=True, null=True, related_name='derived_words',
    related_query_name='derived_word')

There is a field derived_from_word which shows that some of the words are derived from some other word. If it is not derived from any word so the field value is NULL.

What issue i am having that when i register this model in the django-admin and when i opened any of the word for editing, the derived_from_word field is listing all the words and i can not find a way for it to list only the derived word or the NULL value. Due to high load of the words the drop down list is making the page unresponsive.

yekose
  • 33
  • 7

2 Answers2

1

Since Django 2.0 you can use autocomplete_fields to change the select to an auto complete search field that will load options asynchronously

class WordsAdmin(admin.ModelAdmin):
    search_fields = ['bare', 'accented']
    autocomplete_fields = ['derived_from_word']
Iain Shelvington
  • 31,030
  • 3
  • 31
  • 50
0

You can use this for filtering your query set: filter foreignkey field in django admin

Or use the "raw_id_fields" variable for your ModelAdmin to be able to just enter the ID of your instance.

jTiKey
  • 696
  • 5
  • 13