如何将对象从模型A复制到模型B [英] Howto copy object from model A to model B
本文介绍了如何将对象从模型A复制到模型B的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有这个模型类:
class Article(models.Model):
[many fields]
class ArticleArchive(models.Model):
[same fields as Artilce model]
,我想从Article表中获取对象并将其移至ArticleArchive表:
and I want to get objects from Article table and move it to ArticleArchive table:
articles = Article.objects.filter(date__year=2011)
for art in articles:
[and there moving objects]
如何执行?
推荐答案
articles = Article.objects.filter(date__year=2011).values()
for art in articles:
ArticleArchive.objects.create(**art)
这篇关于如何将对象从模型A复制到模型B的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文