简单的问题。我有这个模型:
class Discount(models.Model):
discount_target = GenericForeignKey('content_type', 'object_id')
content_type = models.ForeignKey(ContentType, on_delete=models.CASCADE, blank=True, null=True)
object_id = models.PositiveIntegerField(blank=True, null=True)
如何获取对象
GenericForeignKey
是指?
最佳答案
您只需像访问任何其他字段一样访问它。
my_discount_obj.discount_target
关于 Django 。如何获取GenericForeignKey对应的对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48418562/