我的型号很少。假设在home.html中,我正在使用Page模型通过管理面板创建简单的页面结构。现在,我想添加并在页面内显示多个画廊。我该怎么做?可以在Gallery模型的内部页面模型字段(在我的管理面板中)吗?
class Page(models.Model):
title = models.CharField(max_length=254)
slug = models.SlugField(unique=True)
is_active = models.BooleanField(efault=True)
display_order = models.IntegerField(default=1)
meta_title = models.CharField(max_length=100, null=True, blank=True)
meta_description = models.TextField(null=True, blank=True)
content = RichTextUploadingField(null=True, blank=True)
created = models.DateTimeField(auto_now_add=True)
objects = models.Manager()
class Meta:
verbose_name = 'Home page'
verbose_name_plural = verbose_name
def __str__(self):
return self.title
class Gallery(models.Model):
title = models.CharField(max_length=100)
img = OptimizedImageField(upload_to='gallery')
display = models.BooleanField(default=True)
created = models.DateTimeField(auto_now_add=True)
objects = models.Manager()
class Meta:
verbose_name = 'Gallery'
verbose_name_plural = verbose_name
def __str__(self):
return f'{self.id} {self.title}'