以下关于article.tag_set.add(tag)这一条代码有点似懂非懂口否为我解惑
##能不能详细介绍一下它的添加方式怎么怎么运行的
#models.py
class Article(models.Model):
title = models.CharField(max_length=100)
content = models.TextField()
class Meta:
db_table = 'article'
class Tag(models.Model):
name = models.CharField(max_length=50)
tags = models.ManyToManyField("Article")
class Meta:
db_table = 'tag'
#views.py
def index(request):
article = Article.objects.first()
tag = Tag(name='热门标签')
tag.save()
article.tag_set.add(tag)
return HttpResponse("asdfghjk")