有人问过类似的问题,但没有一个对我有用
下面是我的contentype模型
class notifyall(models.Model):
target_instance=models.ForeignKey(ContentType,null=True,on_delete=models.CASCADE,blank=True)
object_id=models.PositiveIntegerField(null=True)
target_object=GenericForeignKey('target_instance', 'object_id')
如您所见,contentype有一个GenericForeignKey来存储来自不同模型的不同类型的对象
当notifyall对象被创建时,这就是我将得到的
>>object_id= e.g 20
>>target_instance = class_name_of_model
检索notifyall模型中存储的对象作为object\u id和target\u instance的正确方法是什么
请给我你的答案或建议的代码库
目前没有回答
相关问题 更多 >
编程相关推荐