Issue
I'm trying to achieve something apparently simple but I couldn't find any answer, neither on Google nor here. I have a Django model, something dead-simple:
class Shipment(models.Model):
id = models.AutoField(primary_key=True)
transaction = models.ForeignKey(Transaction)
I would like to be able to search in my Shipment Admin page by transaction.id. To clarity, I want this (this code obviously doesn't work):
class ShipmentAdmin(admin.ModelAdmin):
list_display = ('id', 'transaction')
search_fields = ['id', 'transaction.id']
This can't work cause transaction.id does not name a field. Any idea? By "search" I mean be able to insert my transaction id inside the search box of the Shipment Admin page, press "search" and automatically retrieve appropriate transactions.
Solution
as with the other admin options, you need to use __ for foreign keys e.g.
search_fields = ['id', 'transaction__id']
Answered By - JamesO
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.