Answer the question
In order to leave comments, you need to log in
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="Размер",
)
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'
)
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question