The database model of the creation blog of Django Building blog system

Source: Internet
Author: User
Tags virtual environment

Before we had created the virtual environment and started a project.

Now that we're going to add some functional code, Django encourages us to put the code we've written into the app, and each app implements a feature.

Now create a new blog app

1, in the virtual environment into the root directory, run Python manage.py startapp blog. Built a blog app called Apps.

2, in setting.py ' Tell ' Django there is an app like this.

Well, we already have the blog this app, is to achieve blog posts, blog posts should contain the title, text, author, publication time and other data. A more modern blog post also wants it to be categorized, tagged, commented, and so on. To better store this data, we need to properly organize the table structure of the database.

For example, the database table label and classification, there is a lot of duplication of data, this we have to create a new table for them, and then associate them together.

Need to note:

1, all need to inherit from models. Model class

2, the relationship between the tables, ForeignKey represents a one-to-many relationship, such as an article has only one classification, but a classification can correspond to many articles.

Manytomanyfield An article can have a number of tags, a label can have many articles.

Writing the application of the models.py in principle has been said, no longer repeat.

The database model of the creation blog of Django Building blog system

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.