F
F
fantom00052015-12-24 13:41:38
Django
fantom0005, 2015-12-24 13:41:38

How to implement a search in the admin panel for ForeignKey objects in django?

Hello.
I have a model order and a product. To link these tables, a many to many model was created. This intermediate table contains two ForeignKey products and orders.
A setting for an order has been created in the admin panel and an intermediate table has been added inline. There are a lot of products and the drop-down list is large. How can I organize a product search by product so that I can find a product by name or article number.
Here is the many to many table code

lass OrderProduct(models.Model):
  product = models.ForeignKey(
    Product, 
    verbose_name="Продукт"
    )
  order = models.ForeignKey(Order)
  size = models.CharField(
    max_length=30,
    default="",
    verbose_name="Размер",
  )

And this is the admin code.
class ProductOrderInLine(admin.StackedInline):
  model = OrderProduct

  extra = 1

class OrderAdmin(admin.ModelAdmin):
  inlines = [ProductOrderInLine]
  list_display = (
    '__str__',
    'order_name',
    'order_phone',
    'order_status',
    'order_price'
  )

In general, guys, tell me how to dodge)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Andrey K, 2015-12-24
@fantom0005

Recommend https://github.com/yourlabs/django-autocomplete-light

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question