我在Django應用程序中有以下模型: 如何獲取此模型中任何選定content_object的「name」屬性並將其顯示在modelAdmin類的list_display中只顯示GenericForeign Key對象的鍵。請真的需要幫助。獲取GenericForeign鍵對象的名稱屬性
class Checkout(models.Model):
checkout_date = models.DateTimeField(auto_now_add=True)
updated = models.DateTimeField(auto_now=True)
check_in_complete = models.BooleanField(default=False, editable=False)
content_type = models.ForeignKey(ContentType,
limit_choices_to={"model__in": ('Facilitator', 'Enumerator', 'Tutor')})
object_id = models.PositiveIntegerField(verbose_name='Receiver')
content_object = GenericForeignKey('content_type', 'object_id')
你試過'my_checkout.content_object.name'嗎? – Selcuk