阅读背景:

AttributeError:“ManyRelatedManager”对象没有属性“add”?我喜欢django的网站,但是我犯了这个错误

来源:互联网 
for item in data:
    category_id = item['category_id']
    del item['category_id']

    category = Category.objects.get(pk=category_id)

    code = item['code']

    try:
        article = Article.objects.get(pk=code)
    except:
        article = Article(**item)
        article.save()

    # at this point I have the article & category, but the next
    # statement throws me an error:
    category.articles.add(article)
    category.save()
for item in data:
    category_id = item['categ



你的当前访问异常,请进行认证后继续阅读剩余内容。

分享到: