python_day21 DjangoAjax,Cookies&Session,博客系统

'''
in python:

      json.dumps()
      json.loads()

in js:

      JSON.stringfy()
      JSON.parse()

'''

ajax

    form
	地址栏
	a标签
	ajax

	
	
	参数:
	        contentType:客户端告诉服务端 这次发送数据的编码格式
			
	        application/x-www-form-urlencoded:    ?user=yuan&pwd=123

			application/json        :       {"yuan":"","";""}

			server:
				 
			request.body:   "{"yuan":"","";""}"

			request.POST :{"yuan":""}
			request.GET

form组件


---------------------------------

博客系统(博客园)----两天


1、基于ajax实现登录,注册(******)

系统首页
   
个人站点

文章详细页

class Blog():
      '''
	  个人站点表
	  '''
      nid=.....
	  url=""
	  theme=""


class UserInfo():
      nid=......
	  username=.......
	  password=........
	  blog=model.OnetoOne("Blog") 
	  
	  
class Article():
        nid = models.AutoField(primary_key=True)
		title = models.CharField(max_length=50, verbose_name='文章标题')
		desc = models.CharField(max_length=255, verbose_name='文章描述')
		
		comment_count= models.IntegerField(default=0)
		up_count = models.IntegerField(default=0)
		down_count = models.IntegerField(default=0)
		
		create_time = models.DateTimeField(verbose_name='创建时间')
		
		user=models.Foreignkey("userInfo")
		articleDetail=models.OneToOne("ArticleDetail")
		homecategory=models.Foreignkey("Homecategory")
		
		tags=models.ManyToMany("Tag")
		
		
		
class Article2tag():
      nid=......
      article_id=models.Foreignkey("Article")  
      tag_id=models.Foreignkey("Tag")  
		
	  
class ArticleDetail():
      pass	  
	  
class Homecategory():
      name=.....
	  
class Tag():
      name=......	  
	  
class ArticleUp():
      nid=.....
	  user_id=models.Foreignkey("userInfo")
	  article_id=models.Foreignkey("Article")
	  is_up=models.BoolFiled(d..=True)
	  
		nid  user_id   article_id   is_up
		 1      3          4         True

		 2      4          4         False
    
class CommentUp():
      user_id=models.Foreignkey("userInfo")
      comment_id=models.Foreignkey("Comment") 
	
class Comment():

      nid =....
	  create_time=........
	  user_id=models.Foreignkey("userInfo")
      article_id=models.Foreignkey("Article")
      content=.......
	  parent_comment=model.Foreignkey("self",default=null)
	  
	  
	  alex 1
	  egon 2
	  wu   3
	  
	  
	  
	  1
	     2
		   3
	  
      nid 	  user_id  article_id content parent_comment
	  
	   1         1        3         666        null
       2         2        3         6个求       1	
       3         3        3         挺好        2	   
	  
	  
	  
===============================================


----------------------------------------------


from django.db import models

# Create your models here.

from django.db import models

# Create your models here.
from django.contrib.auth.models import AbstractUser


class UserInfo(AbstractUser):


    """
    用户信息
    """


    nid = models.AutoField(primary_key=True)
    nickname = models.CharField(verbose_name='昵称', max_length=32)
    telephone = models.CharField(max_length=11, blank=True, null=True, unique=True, verbose_name='手机号码')
    avatar = models.FileField(verbose_name='头像',upload_to = 'avatar/',default="avatar/default.png")
    create_time = models.DateTimeField(verbose_name='创建时间', auto_now_add=True)
    blog = models.OneToOneField(to='Blog', to_field='nid',null=True)
    

    def __str__(self):
        return self.username



class Blog(models.Model):

    """
    博客信息
    """
    nid = models.AutoField(primary_key=True)
    title = models.CharField(verbose_name='个人博客标题', max_length=64)
    site = models.CharField(verbose_name='个人博客后缀', max_length=32, unique=True)
    theme = models.CharField(verbose_name='博客主题', max_length=32)

    def __str__(self):
        return self.title

class HomeCategory(models.Model):
    """
    博主个人文章分类表
    """

    nid = models.AutoField(primary_key=True)
    title = models.CharField(verbose_name='分类标题', max_length=32)
    blog = models.ForeignKey(verbose_name='所属博客', to='Blog', to_field='nid')

    def __str__(self):
        return self.title

    class Meta:
        verbose_name = 'category'
        verbose_name_plural = 'category'
        ordering = ['title']

class Article(models.Model):

    nid = models.AutoField(primary_key=True)
    title = models.CharField(max_length=50, verbose_name='文章标题')
    desc = models.CharField(max_length=255, verbose_name='文章描述')
    read_count = models.IntegerField(default=0)
    comment_count= models.IntegerField(default=0)
    up_count = models.IntegerField(default=0)
    down_count = models.IntegerField(default=0)
    create_time = models.DateTimeField(verbose_name='创建时间')

    homeCategory = models.ForeignKey(verbose_name='文章类型', to='HomeCategory', to_field='nid', null=True)
    user = models.ForeignKey(verbose_name='作者', to='UserInfo', to_field='nid')

    tags = models.ManyToManyField(
        to="Tag",
        through='Article2Tag',
        through_fields=('article', 'tag'),
    )

   

    def __str__(self):
        return self.title

class ArticleDetail(models.Model):
    """
    文章详细表
    """
    nid = models.AutoField(primary_key=True)
    content = models.TextField(verbose_name='文章内容', )

    article = models.OneToOneField(verbose_name='所属文章', to='Article', to_field='nid')

class Comment(models.Model):

    """
    评论表
    """

    nid = models.AutoField(primary_key=True)
    article = models.ForeignKey(verbose_name='评论文章', to='Article', to_field='nid')
    content = models.CharField(verbose_name='评论内容', max_length=255)
    create_time = models.DateTimeField(verbose_name='创建时间', auto_now_add=True)

    parent_comment = models.ForeignKey('self', blank=True, null=True, verbose_name='父级评论')
    user = models.ForeignKey(verbose_name='评论者', to='UserInfo', to_field='nid')

    up_count = models.IntegerField(default=0)

    def __str__(self):
        return self.content

class ArticleUpDown(models.Model):

    """
    点赞表
    """
    nid = models.AutoField(primary_key=True)
    user = models.ForeignKey('UserInfo', null=True)
    article = models.ForeignKey("Article", null=True)
    is_up = models.BooleanField(default=True,verbose_name='是否赞')
    class Meta:
        unique_together = [
            ('article', 'user'),
        ]

class CommentUp(models.Model):

    """
    点赞表
    """

    nid  = models.AutoField(primary_key=True)
    user = models.ForeignKey('UserInfo', null=True)
    comment = models.ForeignKey("Comment", null=True)

class Tag(models.Model):

    nid = models.AutoField(primary_key=True)
    title = models.CharField(verbose_name='标签名称', max_length=32)
    blog = models.ForeignKey(verbose_name='所属博客', to='Blog', to_field='nid')

    def __str__(self):
        return self.title

class Article2Tag(models.Model):

    nid = models.AutoField(primary_key=True)
    article = models.ForeignKey(verbose_name='文章', to="Article", to_field='nid')
    tag = models.ForeignKey(verbose_name='标签', to="Tag", to_field='nid')

    def __str__(self):
        return self.article.title+"--"+self.tag.title

    class Meta:
        unique_together = [
            ('article', 'tag'),
        ]







	  
	  
	  
	  
	  
	  

	  
	  

  

posted @ 2017-12-08 09:53  jing_1  阅读(171)  评论(0编辑  收藏  举报