Python 如何通过模型的方法django更新对象

Python 如何通过模型的方法django更新对象,python,django,Python,Django,我需要编写通过参数传递的方法,即update对象。比如说: class ArticlesSerie(models.Model): title = models.CharField(max_length=120) def add_article(self, article): article.serie = self article.save() 和示范条文: class Article(models.Model): ...

我需要编写通过参数传递的方法,即update对象。比如说:

class ArticlesSerie(models.Model):
    title = models.CharField(max_length=120)


    def add_article(self, article):
         article.serie = self
         article.save()
和示范条文:

class Article(models.Model):
    ...
    serie = models.ForeignKey(ArticlesSerie, blank=True, null=True)
    ...
但当我尝试在shell中使用方法add_article时,此代码会导致错误:

a = Article.objects.get(id=4)
b = ArticlesSerie.objects.get(id=1)
b.add_article(a)

UserWarning: update is not implemented in this backend

我该怎么办?

如官方文件所示,您只需将新文章添加到(相关文章的)系列中即可

如您所见,可能不值得使用特定的方法,因为它是一个单行程序,除非您希望执行进一步的检查(例如,在文章的字段上)


注:您可能需要考虑使用<代码>创建< /COD>而不是<代码> Addio>代码>,如果您不需要预先实例化文章。

您在哪里得到错误?不清楚您想做什么我在
shell中测试它
请提供一个完整的模型类(es)测试什么?什么叫添加文章?什么是自我?错误从何而来?仍然没有显示您正在做什么/如何调用它
class ArticlesSerie(models.Model):
    title = models.CharField(max_length=120)

    def add_article(self, article):
         self.article_set.add(article)