I have models: category, product and product description. Because There are too many products and finding the right product to add a description is simply impossible; you need to solve this problem:

Option 1 - search for a product knowing its ForeignKey.

Option 2 - first select the product category, and then the product.

  • So what is the question? - Yurich
  • Found "django-autocomplete-light", try it ... Are there any other search options for ForeignKey? - Vladimir Saleev

2 answers 2

To search the admin in the admin class you need to register:

search_fields = ('pk',)

In this case, the search by id will be implemented. A comma can add more fields, which will be implemented search

  • This is sort of a search by objects, but I need a search when adding an object, a search by ForeignKey - Vladimir Saleev
  • then add the line raw_id_fields = ("pk",) to the class - Ildan Kiamov

Product search by id:

good = Good.objects.get(pk=good_id)

Search for a product from a specific category by product id and category id:

good = Good.objects.get(pk=good_id, cat__id=cat_id)

  • Does it work in the admin django? - Vladimir Saleev
  • Was it really said what to look for in the admin panel? - Ildan Kiamov
  • Forgot to specify it. I know about filtering, but as in the admin area .. - Vladimir Saleev