这是我的models.py。以文件夹结构格式显示。
class Folder(models.Model):
user = models.ForeignKey(User, on_delete=models.CASCADE, related_name='userfolders')
folder = models.ForeignKey("self", on_delete=models.CASCADE,related_name='folders', null=True, blank=True)
name = models.CharField(_('Folder Name'), max_length=70)
class File(models.Model):
user = models.ForeignKey(User, on_delete=models.CASCADE, related_name='userfiles')
folder = models.ForeignKey(Folder, on_delete=models.CASCADE, related_name='folderfiles')
description = models.CharField(_('File Description'), max_length=70)
location = models.FileField(_('Location of the File'), upload_to=file_location_path, null=True, blank=True)
在模型中,您可以看到我有一个带有外键的文件夹,并且文件可以与文件夹关联。
Folder------+---Old Folder
+---Folder1-+--Cats.jpg
| +--File1.jpg
+---File1.txt
File
Folder New -+---Puppy.jpg
+---Dogs----+--Dog1.jpg
+--Dog2.jpg
+--Dog3.jpg
| 1st level | 2nd level | 3rd level |
我如何首先显示第一个级别,然后如果用户选择一个文件夹,则它应该显示其内容。例如,如果选择“新建文件夹”,则用户应看到名为Puppy.jpg的文件和名为Dogs的文件夹。这可能吗?