“蓝鲸Django: 显示用户的评论与点赞”的版本间的差异

来自CloudWiki
跳转至: 导航搜索
admin后台中手动添加数据
admin后台中手动添加数据
第55行: 第55行:
 
[[文件:bd20-5-31.png]]
 
[[文件:bd20-5-31.png]]
  
[[文件:bd20-5-32.png]]
+
[[文件:bd20-5-33.png]]

2020年6月14日 (日) 01:58的版本

实现点赞功能

点赞功能后台接口

moments.models.py:

class Reply(models.Model):
    status = models.ForeignKey(Status,models.CASCADE)
    author = models.CharField(max_length=50)
    type = models.CharField(max_length=20,choices=[("0","like"),("1","comment")])
    at_person = models.CharField(max_length=50,null=True,blank=True)
    text = models.CharField(max_length=280,null=True,blank=True)

    def __str__(self):
        return "{} on {}".format(self.author,self.status.text)


生成表

[root@localhost wechat]# python3 manage.py makemigrations

Migrations for 'moments':
  moments/migrations/0002_auto_20200614_0926.py
    - Create model Reply
    - Change Meta options on status
    - Alter field motto on wechatuser
    - Alter field pic on wechatuser
    - Add field status to reply


[root@localhost wechat]# python3 manage.py migrate

Operations to perform:
  Apply all migrations: admin, auth, contenttypes, moments, sessions
Running migrations:
  Applying moments.0002_auto_20200614_0926... OK

在admin中管理Reply表

admin.py:

from django.contrib import admin
from .models import WeChatUser, Status, Reply
# Register your models here.


admin.site.register(WeChatUser)
admin.site.register(Status)
admin.site.register(Reply)



admin后台中手动添加数据

Bd20-5-30.png

Bd20-5-31.png

Bd20-5-33.png