Python3 Advanced Development-the first Imitation Blog Park project (1)

Source: Internet
Author: User

First we will design the table structure:

UserInfo (user information Form)--------"one-to-one-----------" blog (blog Information sheet)

UserInfo (User information Sheet)---------"one-to-many-----------" article UpDown (likes table)

UserInfo (User information Sheet)---------"one-to-many-----------" article Comment (comment form)

UserInfo (User information Sheet)----------"one-to-many-----------" article (article)

Blogs (blog information table)----------------"one-to-many-----------" category (personal blog post classification)

Blogs (blog information table)----------------"one-to-many------------" tag (tag table)

Category (Personal blog Article classification table)--"one to many-------------" article (article table)

Tag (tag table)--------------------------"Many-to-many-------------" article (article table)

Article (article table)------------------------"one to one-------------" articledetail (Article detail table)

Article (article table)------------------------"one-to-many--------------" article UpDown (likes table)

Article (article table)------------------------"one-to-many---------------" article Comment (comment form)

 fromDjango.dbImportModels#Create your models here. fromDjango.contrib.auth.modelsImportAbstractuserclassUserInfo (abstractuser):"""User Information Table"""nid= Models. Autofield (primary_key=True) Phone= Models. Charfield (max_length=11, Null=true, unique=True) Avatar= Models. Filefield (upload_to="avatars/", default="Avatars/default.png") Blog= Models. Onetoonefield (to="Blog", to_field="nid", null=True)def __str__(self):returnSelf.usernameclassMeta:verbose_name="User Information"verbose_name_plural=Verbose_nameclassBlog (models. Model):"""Blog Information"""nid= Models. Autofield (primary_key=True) Title= Models. Charfield (max_length=64)#Personal Blog TitleTheme = models. Charfield (MAX_LENGTH=32)#Blog Topics    def __str__(self):returnSelf.titleclassMeta:verbose_name="Blog"verbose_name_plural=Verbose_nameclassCategory (models. Model):"""personal blog post categories"""nid= Models. Autofield (primary_key=True) Title= Models. Charfield (MAX_LENGTH=32)#category HeadingsBlog = models. ForeignKey (to="Blog", to_field="nid")#Foreign Key Association blog, a blog site can have multiple categories    def __str__(self):return "{}-{}". Format (Self.blog.title, Self.title)classMeta:verbose_name="article Categories"verbose_name_plural=Verbose_nameclassTag (models. Model):"""label"""nid= Models. Autofield (primary_key=True) Title= Models. Charfield (MAX_LENGTH=32)#Label nameBlog = models. ForeignKey (to="Blog", to_field="nid")#Affiliated Blog    def __str__(self):returnSelf.titleclassMeta:verbose_name="label"verbose_name_plural=Verbose_nameclassarticle (models. Model):"""article"""nid= Models. Autofield (primary_key=True) Title= Models. Charfield (MAX_LENGTH=50)#article titledesc = models. Charfield (max_length=255)#Article DescriptionCreate_time = models. Datetimefield (Auto_now_add=true)#creation TimeCategory = Models. ForeignKey (to="Category", to_field="nid", null=True) User= Models. ForeignKey (to="UserInfo", to_field="nid") Tags=models. Manytomanyfield ( to="Tag", through="Article2tag", Through_fields=("article","Tag"),    )    def __str__(self):returnSelf.titleclassMeta:verbose_name="article"verbose_name_plural=Verbose_nameclassArticledetail (models. Model):"""Article details Table"""nid= Models. Autofield (primary_key=True) Content=models. TextField () Article= Models. Onetoonefield (to="article", to_field="nid")    classMeta:verbose_name="article details"verbose_name_plural=Verbose_nameclassArticle2tag (models. Model):"""Many-to-many relationship tables for articles and labels"""nid= Models. Autofield (primary_key=True) Article= Models. ForeignKey (to="article", to_field="nid") Tag= Models. ForeignKey (to="Tag", to_field="nid")    def __str__(self):return "{}-{}". Format (self.article, Self.tag)classMeta:unique_together= (("article","Tag"),) Verbose_name="Articles-Tags"verbose_name_plural=Verbose_nameclassArticleupdown (models. Model):"""Click like table"""nid= Models. Autofield (primary_key=True) User= Models. ForeignKey (to="UserInfo", null=True) Article= Models. ForeignKey (to="article", null=True) is_up= Models. Booleanfield (default=True)classMeta:unique_together= (("article","User"),) Verbose_name="Click to praise"verbose_name_plural=Verbose_nameclassComment (models. Model):"""comment Form"""nid= Models. Autofield (primary_key=True) Article= Models. ForeignKey (to="article", to_field="nid") User= Models. ForeignKey (to="UserInfo", to_field="nid") Content= Models. Charfield (max_length=255)#Comment ContentCreate_time = models. Datetimefield (auto_now_add=True) parent_comment= Models. ForeignKey (" Self", null=True)def __str__(self):returnself.contentclassMeta:verbose_name="Reviews"verbose_name_plural= Verbose_name

Python3 Advanced Development-the first Imitation Blog Park project (1)

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.