AttributeError: 'ManyRelatedManager' objet n'a pas d'attribut "ajouter"? Je fais comme dans le site web de django mais eu cette erreur

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()

L'erreur est:

   AttributeError: 'ManyRelatedManager' object has no attribute 'add'
  • Êtes-vous à l'aide d'un modèle? si oui .ajouter et .créer ne fonctionnera pas.
  • Utilisation category.articles.set(category.articles.all() | article) fonctionne sur mon scénario.
InformationsquelleAutor Totty.js | 2011-11-11