这是我的问题
我正在尝试从使用外键连接到主题模型的页面模型中获取数据。有没有办法快速获取数据?
这是我的 views.py
网址.py
我正在尝试从 page_set.filter 对象中获取字段标题。
这是我的models.py
from django.db import models
from ckeditor.fields import RichTextField
# Create your models here.
class Subject(models.Model):
title = models.CharField(max_length = 200)
slug = models.SlugField(blank = False)
visible = models.BooleanField(default = True)
position = models.IntegerField()
date_published = models.DateTimeField(auto_now_add = True)
date_updated = models.DateTimeField(auto_now_add=False)
def __str__(self):
return self.title
class Page(models.Model):
subject = models.ForeignKey(Subject, on_delete= models.CASCADE)
title = models.CharField(max_length = 200)
slug = models.SlugField(blank = False)
description = models.TextField()
thumbs = models.ImageField(blank = True)
visible = models.BooleanField(default = True)
position = models.IntegerField()
date_published = models.DateTimeField(auto_now_add = True,auto_now=False)
date_updated = models.DateTimeField(auto_now_add=False, auto_now=True)
def __str__(self):
return self.title
一只萌萌小番薯
相关分类