Django 管理中的多对多问题

发布于 2024-09-16 07:42:03 字数 317 浏览 6 评论 0原文

我本质上是在 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 :)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

人间不值得 2024-09-23 07:42:03

您忘记在 ManyToManyField 声明中指定 blank=True

class Article(models.Model):
    tags = models.ManyToManyField(ArticleTag, blank=True, 
        related_name="articles")

此外,是否有一种相当简单的方法来创建控件以方便根据堆栈溢出或好吃的.com 进行标记?

没有任何内置内容,但有几个 Django 附加库可以进行标记。其中之一可能适合您的需求。

You forgot to specify blank=True in your ManyToManyField declaration:

class Article(models.Model):
    tags = models.ManyToManyField(ArticleTag, blank=True, 
        related_name="articles")

Also, is there a fairly easy way to create a control to facilitate tagging as per stack overflow or delicious.com?

There's nothing built-in, but there are several add-on libraries for Django that do tagging. One of them might fit your needs.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文