评论与子评论
1.評論與子評論
在創建數據表時,評論與子評論可以進行自相關,這樣方便增刪改查
class Commit(models.Model):nid = models.AutoField(primary_key=True)user = models.ForeignKey(to='UserInfo', to_field='nid')article = models.ForeignKey(to='Article', to_field='nid')content = models.CharField(max_length=255)create_time = models.DateTimeField(auto_now_add=True)# 這樣寫是可以的# parent_id=models.IntegerField()# 自關聯# parent_id=models.ForeignKey(to='Commit',to_field='nid')parent = models.ForeignKey(to='self', to_field='nid',null=True,blank=True) View Code?
轉載于:https://www.cnblogs.com/xufengnian/p/10604978.html
總結
- 上一篇: APICloud学习第二天——操作云数据
- 下一篇: MySQL:参数wait_timeout