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()
什么是现在想知道的是,我以后保存对象,我怎么能获取对象和其他属性的主键的新对象?
保存后对象中是否已存在id?尝试new_document.id – szaman
或new_document.pk,以防您的主键字段有其他名称 –
此代码中的“self”是什么?代码从哪里来? – miki725