直接上代碼
class Article(models.Model):
nid = models.BigAutoField(primary_key=True)
title = models.CharField(max_length=50, verbose_name='文章標(biāo)題')
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='創(chuàng)建時(shí)間')
class ArticleDetail(models.Model):
"""
文章詳細(xì)表
"""
nid = models.AutoField(primary_key=True)
content = models.TextField(verbose_name='文章內(nèi)容', )
article = models.OneToOneField(verbose_name='所屬文章', to='Article', to_field='nid')
從Article去查找ArticleDetail的相關(guān)信息是反向查詢
但是在模板語法中怎么使用呢考廉?
以下是模板語法
注意在反向時(shí)直接也時(shí)使用表明,但是表名一定要小寫