• Python之路,day20-django基础


    Python之路,day20-django基础

    models.py

      

    from django.db import models
    from django.contrib.auth.models import User
    
    # Create your models here.
    
    class UserProifle(models.Model):
        user = models.OneToOneField(User,null=True, default=None)
        name = models.CharField(max_length=32,null=True)
    
        def __str__(self):
            return self.name
    
    class Article(models.Model):
        """文章表"""
        title = models.CharField(max_length=128,unique=True)
        author = models.ForeignKey("UserProifle")
        category = models.ForeignKey("Category")
        pub_date = models.DateTimeField(auto_now_add=True,auto_created=True)
        tags = models.ManyToManyField("Tag",null=True)
        body = models.TextField(max_length=100000)
        head_img = models.ImageField(upload_to="uploads")
        status_choices = ((0,'草稿'),(1,'发布'),(2,'隐藏'))
        priority = models.SmallIntegerField(default=1000,verbose_name="优先级")
    
        def __str__(self):
            return self.title
    
    class Category(models.Model):
        """板块"""
        name = models.CharField(max_length=64,unique=True)
        set_as_top_menu = models.BooleanField(default=True)
    
        def __str__(self):
            return self.name
    
    
    class Tag(models.Model):
        """标签表"""
        name = models.CharField(max_length=64, unique=True)
        def __str__(self):
            return self.name
    
    class Comment(models.Model):
        """评论"""
        article = models.ForeignKey("Article")
        #p_node = models.ForeignKey("Comment",null=True)
        p_node = models.ForeignKey("Comment", null=True, blank=True, related_name="my_child_comments")
        user = models.ForeignKey("UserProifle")
        date = models.DateTimeField(auto_now_add=True)
        comment = models.TextField(max_length=1024)
    
    
        def __str__(self):
            return self.comment
    
    class Like(models.Model):
        """点赞"""
        article = models.ForeignKey("Article")
        user = models.ForeignKey("UserProifle")
        date = models.DateTimeField(auto_now_add=True)
    
    
    class PrivateMail(models.Model):
        """私信"""
        pass
    

      admin.py

    from django.contrib import admin
    from bbs import models
    # Register your models here.
    
    admin.site.register(models.Article)
    admin.site.register(models.UserProifle)
    admin.site.register(models.Tag)
    admin.site.register(models.Comment)
    admin.site.register(models.Like)
    admin.site.register(models.PrivateMail)
    admin.site.register(models.Category)
    

    python manage.py startapp bbs  

    python manage.py makemigrations

    python manage.py migrate

    python manage.py createsuperuser

    python manage.py runserver 127.0.0.1:8000

  • 相关阅读:
    str_replace函数的使用规则和案例详解
    phpqrcode.php 生成二维码图片用于推广
    常用的正则表达式验证
    Java:原生javaWeb下载pdf文件
    设计模式:七大原则
    Spring Boot:整合Hikari+Oracle+p6spy
    Spring Boot:开启全局事务
    Java8:按照对象的属性,对List集合分组
    SpringMVC统一异常处理
    JSR303校验的基本使用和结合AOP使用
  • 原文地址:https://www.cnblogs.com/heshaochuan/p/6616171.html
Copyright © 2020-2023  润新知