我本质上是在 django 中创建一个博客应用程序,作为学习诀窍和提高 django 技能水平的一种方式。我基本上有一个多对多的关系,但我在管理站点中遇到了问题。我有两种主要类型,Article 和 ArticleTag。许多文章可以属于许多文章标签,并且关系应该是双向的,以便能够从任何一方“遵循”该关系。
我遇到的问题是,在管理面板中,当我要创建新文章时,它不允许我在不创建新文章标签的情况下创建新文章,而如果不创建新文章则无法创建新文章标签,等等我怎样才能使这些正常工作并且是可选的?另外,是否有一种相当简单的方法来创建一个控件以方便根据堆栈溢出或好吃的.com 进行标记?我对管理系统相当陌生:)
I am essentially creating a blog application in django as a way of learning the ropes and boosting my skill level in django. I basically have a many-to-many relationship that I am having problems with in the admin site. I have two main types, Article and ArticleTag. Many Articles can belong to many ArticleTags, and the relationship should be bidirectional so as to be able to "follow" the relationship from either side.
The problem I am having is that in the admin panel, when I go to create a new Article, it will not allow me to create a new Article without creating a new ArticleTag, which can't be created without creating a new Article, etc. How can I make these work properly and be optional? Also, is there a fairly easy way to create a control to facilitate tagging as per stack overflow or delicious.com? I am fairly new to the admin system :)
发布评论
评论(1)
您忘记在
ManyToManyField
声明中指定blank=True
:没有任何内置内容,但有几个 Django 附加库可以进行标记。其中之一可能适合您的需求。
You forgot to specify
blank=True
in yourManyToManyField
declaration:There's nothing built-in, but there are several add-on libraries for Django that do tagging. One of them might fit your needs.