1👍
✅
You can modify the __str__
method in the OrderItem model to include the order information.
You can access the related order object through the foreign key order and retrieve the order id property. Check this code and update accordingly:
class OrderItem(models.Model):
# ... other fields ...
def __str__(self):
return 'OrderItem#' + str(self.id) + '-Order#' + str(self.order.id)
Once you make this change, the OrderItem’s string representation on the admin page will show the desired format as you wanted.
Source:stackexchange.com