链接数据库中的 2 个属性
我们正在寻求建议以找到解决此问题的方法:
我们认为我们有以下数据库表
Article (id, title, content)
我们在此表上存储 2 篇文章
article1(1, title1, content1)
article2(2, title2, content2)
主键是 id,我们想知道是否有一种方法可以“链接” Article2.title 与article1.title。例如,如果文章具有相同的标题,我们只想使用一个条目,因此article2.title应该是一种指向article1.title的指针。系统将在将数据存储到数据库之前检查数据,如果 title2 = title1,则应创建一个链接而不插入 title2。
有没有办法用 Python 和任何数据库管理系统来做到这一点?
这是一个学校项目,因此我们将不胜感激任何帮助,
提前谢谢您:-)
We are looking for advice to find a solution to this problem :
We consider that we have the following database table
Article (id, title, content)
We store 2 articles on this table
article1(1, title1, content1)
article2(2, title2, content2)
The primary key is the id and we want to know if there is a way to "link" the article2.title with the article1.title. For example, if the articles have the same title, we want to use only one entry so article2.title should be a kind of pointer to article1.title. The system will check the data before storing it in the database and if title2 = title1, a link should be created without inserting the title2.
There is a way to do that with Python and any database management system ?
It's for a school project, so any help will be really appreciated
Thank you in advance :-)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是 RDBS 101,但我还是会回答。设置一些像这样的模式:
然后您可以使用
INNER JOIN
获取文章和标题。我将把插入内容留给你,但此时它应该非常明显。
至于 CMS 和数据库 ORM,我推荐 Flask 和 SqlAlchemy 分别。然而,Flask 并不是一个 CMS,而是一个易于学习和使用的轻量级 Web 框架。
This is RDBS 101 but I'll answer anyway. Setup some schema like this:
Then you can get the articles and titles using an
INNER JOIN
.I'll leave the inserts up to you, but it should be pretty obvious at this point.
As for a CMS and database ORM, I'd recommend Flask and SqlAlchemy respectively. However, Flask isn't a CMS, but rather a lightweight web framework that's easy to learn and use.