开发者

Link 2 attributes in a database

开发者 https://www.devze.com 2023-01-23 15:49 出处:网络
We are looking for advice to find a solution to this problem : We consider that we have the following database table

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开发者_StackOverflow社区 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 :-)


This is RDBS 101 but I'll answer anyway. Setup some schema like this:

article
    id
    title_id
    content

title
    id
    title

Then you can get the articles and titles using an INNER JOIN.

SELECT
    article.id,
    title.title,
    article.content
FROM article 
INNER JOIN title ON
    title.id = article.title_id

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消