2012-10-04 51 views
0

我节省了使用如何在Django中保存后立即获取对象?

new_document = form.save(commit=False) 
    new_document.object_id = int(self.kwargs['pk']) 
    new_document.content_type = ContentType.objects.get_for_model(self.target_model) 
    # Set the document category 
    new_document.category = self.get_document_category() 
    new_document.save() 

什么是现在想知道的是,我以后保存对象,我怎么能获取对象和其他属性的主键的新对象?

+0

保存后对象中是否已存在id?尝试new_document.id – szaman

+0

或new_document.pk,以防您的主键字段有其他名称 –

+0

此代码中的“self”是什么?代码从哪里来? – miki725

回答

2

您已拥有new_document中的对象。

相关问题